Rails: What is the location option for in the render method

前端 未结 2 805
独厮守ぢ
独厮守ぢ 2021-02-07 09:59

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

2条回答
  •  悲&欢浪女
    2021-02-07 10:26

    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.

提交回复
热议问题