Ruby rails page Jump (render and redirect_to)

Source: Internet
Author: User
Tags example of manual

Ruby Code Copy code The Code is as follows: if @ user. update_attributes (: Password => Params [: User] [: Password])
Flash [: Notice] = 'password changed successfully'
Redirect_to: Action => 'index'
Else
Redirect_to: Action => 'change _ pass',: Id => @ user
End

Later, I changed the next 5th rows and changed redirect_to to render, so it was OK. I found there are many differences between redirect_to and render after searching on the Internet. I didn't even pay attention to it before, Khan ..

Redirect_to implements the jump of the Action method and initiates a new request to the browser. The usage is as follows:Copy codeThe Code is as follows: redirect_to: Action => 'edit',: Id => 7
Redirect_to "http://wiisola.javaeye.com /"
Redirect_to "/images/1.jpg"
Redirect_to: Back

Row 3 shows the last accessed page.
Render can be translated into "rendering". That is to say, render only renders a new template without executing the corresponding action. Render is used as follows:Copy codeThe Code is as follows: render (: text => string)
Render (: inline => string, [: TYPE => "rhtml" | "rxml"])
Render (: Action => action_name)
Render (: file => path, [: use_full_path => true | false])
Render (: template => name)
Render (: Partial => name)
Render (: Nothing => true)
Render ()

Row 3: render the text directly
Row 3: render the input string as a template (rhtml or rxml)
Row 3: directly call an action template, which is equivalent to forward to a view
row 4th: Use a template file render. When use_full_path is set to true, you can pass in the relative path
row 5th: use the Template Name render, E. x.: render (: template => "blog/short_list")
row 6th: rendered as a partial template
row 7th: No output, includes layout
row 8th: Default render, equivalent to render (: Action => Self)
to add an example of manual render:
Ruby Code copy Code the code is as follows: def search
@ Results = search. find (Params [: Query])
case @ results
When 0 then render: Action => "no_results"
when 1 then render: action => "show"
when 2 .. 10 then render: Action => "show_detail"
end
def search
@ Results = search. find (Params [: Query])
case @ results
When 0 then render: Action => "no_results"
when 1 then render: action => "show"
when 2 .. 10 then render: Action => "show_prop"
end

however, my problem persists. Why can't I use redirect_to re-request to Display error messages when rendering a template with render? Maybe the source code can solve the problem, but unfortunately it cannot be understood, Khan... remember the usage of render and redirect_to later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.