Ruby Code
Copy Code code as follows:
If @user. Update_attributes (:p assword => params[:user][:p assword])
Flash[:notice] = ' Password modification complete '
Redirect_to:action => ' index '
Else
Redirect_to:action => ' Change_pass ',: ID => @user
End
Then casually changed the next 5th line, the redirect_to changed to render, incredibly OK. On the internet found that redirect_to and render still have a lot of difference, I used to have no attention, sweat.
REDIRECT_TO implementation is the action method of the jump, to launch a new request to the browser, the specific use of the following methods:
Copy Code code as follows:
Redirect_to:action => ' edit ',: ID => 7
Redirect_to "http://wiisola.javaeye.com/"
Redirect_to "/images/1.jpg"
Redirect_to:back
The 4th line is to go back to the page that you visited last time.
Render can be translated as "render", that is, render only renders a new template without executing the appropriate action. The use of render is as follows:
Copy Code code 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 (:p artial => name)
Render (: Nothing=>true)
Render ()
Line 1th: render the text directly
Line 2nd: Render the incoming string as a template (rhtml or rxml)
Line 3rd: A template that invokes an action directly, equivalent to forward to a view
Line 4th: Using a template file render, you can pass in a relative path when the Use_full_path argument is true
Line 5th: Use template name render,e.x.: Render (: Template => "Blog/short_list")
Line 6th: Rendering with local templates
Line 7th: Nothing is output, including layout
Line 8th: Default render, equivalent to render (: Action => Self)
To fill in a manual render example:
Ruby Code
Copy Code code as follows:
def search
@results =search.find (Params[:query])
Case @results
When 0 then render:action=> "No_results"
When the 1 then render:action=> "Show"
When 2..10 then render:action=> "Show_many"
End
End
def search
@results =search.find (Params[:query])
Case @results
When 0 then render:action=> "No_results"
When the 1 then render:action=> "Show"
When 2..10 then render:action=> "Show_many"
End
End
But my own problem is still not resolved, why use render rendering a template can display error messages, but with redirect_to request is not it? Maybe look at the source can solve it, but do not understand, Khan. In a word, remember render and Redirect_to's usage.