Hey I am wondering what the location option for the render method in rails is. The docs here http://guides.rubyonrails.org/layouts_and_rendering.html states:
"You can use the :location option to set the HTTP Location header:"
But I have no idea why you would do this, or what you would use this for.
Rails can render a raw file from an absolute path. This is useful for conditionally rendering static files like error pages. This renders the raw file (it doesn't support ERB or other handlers). By default it is rendered within the current layout.
By default, if you use the :text option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option.
Rendering is the ultimate goal of your Ruby on Rails application. You render a view, usually . html. erb files, which contain a mix of HMTL & Ruby code. A view is what the user sees.
render :json essentially calls to_json and returns the result to the browser with the correct headers. This is useful for AJAX calls in JavaScript where you want to return JavaScript objects to use. Additionally, you can use the callback option to specify the name of the callback you would like to call via JSONP.
Actually location
option is used to redirect to a new resource as part of processing the request. For example,
render :xml => post.to_xml, :status => :created, :location => post_url(post)
is telling the recipient that a XML file for the post is created and you will get this from post_url(post)
. Hence GO THERE ;)
render
method does this by setting the Location
option in response object
... ... ...
if location = options[:location]
response.headers["Location"] = url_for(location)
end
... ... ...
You can find details about Location
header here http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With