soveran / cuba

Rum based microframework for web development.
http://cuba.is
MIT License
1.44k stars 249 forks source link

Custom res.staus stops rendering on chrome. #96

Closed rangeroob closed 5 years ago

rangeroob commented 5 years ago

On chrome inputting a custom res.staus stops page from rendering html/css/js properly and just prints the html in plain text though it shows the right status.

here is some of my code that displays incorrectly on chrome (works in firefox and edge):

class Login < Cuba; end
  Login.define do
    on get do
      on root do
        res.status = 401
        res.write view('/login')
      end
    end
soveran commented 5 years ago

Hey @rangeroob, I'm trying to reproduce the error but I've had no luck so far.

Here's the code I'm using:

require "cuba"

class Login < Cuba
  def view(str)
    "You are at #{str}"
  end
end

Login.define do
  on get do
    on root do
      res.status = 401
      res.write view('/login')
    end
  end
end

run(Login)

I've tested it with Chrome 74 and the webservers WEBrick and Puma. Can you try the code above ant tell me if it works for you? You can put it in a config.ru file and run rackup.

rangeroob commented 5 years ago

Hey thank you for responding quickly, so it looks like your example code works as well as adding cuba/render and using some view files like layout.erb. So it looks like the error is somewhere within my code specifically and not within cuba. So with that I will close this issue and thank you for responding and hopefully I can get my issue sorted.

rangeroob commented 5 years ago

Hello again I solved my issue by using render instead of res.write view for some reason that solves my issue in Chrome. I was wondering why though? From the documentation it seems they should be the same thing, no?

soveran commented 5 years ago

Can you show me the definition of view and your template?

rangeroob commented 5 years ago

Here is the definition of view:

def view(template, locals = {}, layout = settings[:render][:layout])
  partial(layout, locals.merge(content: partial(template, locals)))
end

And my template

Cuba.settings[:render][:template_engine] = 'html.erb'

I hope this is the correct information needed if there is anything else let me know.