OneZero
OneZero

Reputation: 11904

What does redirect_to @client mean?

Here I have a scaffold for clients, and in the create method in ClientsController,

if @client.save
  redirect_to @client
else
  render :action => "new"
end

Here what it means to redirect to an instance variable of Client class?

Also, in else, render renders the view for new if save fails. However, how does the controller keep the original input at the same place? (For example I fill the form and send it but fail to proceed, so it takes me back to the new client page with my original input at the right place.)

Upvotes: 0

Views: 156

Answers (1)

Ganesh Kunwar
Ganesh Kunwar

Reputation: 2653

redirect_to @client redirects to the clients/show/1 directory. where 1 is the id of client. and render :action => "new" render the new action, for more detail see http://guides.rubyonrails.org/layouts_and_rendering.html

Upvotes: 1

Related Questions