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.