Posted by tobi — 07:18 AM May 26
One of the bigger changes coming in the next rails will be an overhauled render method.
Here are some examples. New syntax in bold.
render_with_layout “weblog/show”, “200 OK”, “layouts/dialog”
render :action => “show”, :layout => “dialog”
render_without_layout “weblog/show”
render :action => “show”, :layout => false *
render_action “error”, “404 Not Found”
*render :action => “error”, :status => “404 Not Found”
render_template “xml.div(‘stuff’)”, “200 OK”, :rxml
render :inline => “xml.div(‘stuff’)”, :type => :rxml *
render_text “hello world!”
*render :text => “hello world!”
render_partial_collection “person”, @people, nil, :a => 1
render :partial => “person”, :collection => @people, :locals => { :a => 1 }
Ben Bleything 26 May 07:29
Seems kind of strange that you need to put an entire HTTP status string in there. I would think rails should handle the translation of error code -> status message.
I foresee a future where people who are inexperienced with the HTTP spec do things like “500 Not Authorized” and “404 Page Moved”. It’s kinda scary.
tobi 26 May 07:39
I’m not sure… I’m not a fan of programming for the dumb. If someone wants to return a non standard response string thats fine with me.
Ben Bleything 26 May 07:55
I don’t really think it’s programming for the dumb. Most of the time I spent really learning web programming was in mod_perl-land, where you’re provided with constants that you can use to return specific things.
I guess it doesn’t really matter until you start talking about the status codes that the user doesn’t see… the 3xx series, for instance. Or, for instance, if you send a 401 when you meant 403.
That’s getting away from my initial concern though. I’ll probably just add some code into my apps so I can use constants when I need to :)
rick 26 May 09:50
I thought I read that they were going to allow numerical status codes. I’m all for this, actually.
So this new render method works now? I saw the check-in, but it didn’t seem to work for me. I’ll try it again…
ToddG 26 May 10:23
I’m not too familiar with this but wouldn’t using constants for status codes make it easier to deal with things like alternate languages?
As in the numerical status code could be a key into a dict that would vary based on the language being used? Or is this a DRY thing?
Tim Lucas 26 May 18:40
“I foresee a future where people who are inexperienced with the HTTP spec do things like “500 Not Authorizedâ€? and “404 Page Movedâ€?. It’s kinda scary.”
The only thing user agents use is the number… so this actually wouldn’t make a difference… apart from confusing the developer and anybody looking at the raw http stream.
You do have a point though about repetition…