Closed rangeroob closed 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
.
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.
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?
Can you show me the definition of view
and your template?
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.
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):