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.