Ruby rails page Jump (render and redirect_to)

Source: Internet
Author: User
Tags example of manual

Ruby code
Copy codeThe 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: directly render the text
Row 2nd: renders the input string into a template (rhtml or rxml)
Row 3rd: directly call the template of an action, which is equivalent to forward to a view.
Row 4th: Use a template file render. When use_full_path is set to true, the relative path can be input.
Row 5th: Use the template Name render, e. x.: render (: template => "blog/short_list ")
Row 3: Partial template Rendering
Row 3: No output, including layout
Row 3: Default render, equivalent to render (: action => self)
Add an example of manual render:
Ruby code
Copy codeThe 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_token"
End
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_token"
End
End

However, my own problem still persists. Why can't I use redirect_to re-request to Display error messages when I use render to render a template? 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.