defcreate
@user = User <http://apidock.com/rails/User>.new
<http://apidock.com/rails/ActionController/Responder/new/class>(params[:user])
flash[:notice] = 'User was successfully created.' if @user.save
respond_with(@user)
end
is the same as:
defcreate
@user = User <http://apidock.com/rails/User>.new
<http://apidock.com/rails/ActionController/Responder/new/class>(params[:user])
respond_to do |format|
if @user.save
flash[:notice] = 'User was successfully created.'
format.html { redirect_to(@user) }
format.xml { render :xml => @user, :status => :created, :location
=> @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status =>
:unprocessable_entity }
end
end
end
It's just built into the method.
Garrett Lancaster
------------------------------------------------------------------------ Mauro <mailto:[email protected]> January 11, 2011 4:11 PM If you don't provide a redirect_to, it will assume a view with name create.html.erb or create.html.haml, etc. and try to render it giving you a missing template. The most common design is create redirects to @model and destroy redirects to index_path.If I put in create respond_with, for example respond_with(@sector) it seems that redirects automatically to show while respond_with(@sector) in destroy redirects to index.How can it know where redirect? --You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.To post to this group, send email to [email protected].To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.------------------------------------------------------------------------ Garrett Lancaster <mailto:[email protected]> January 11, 2011 4:02 PMIf you don't provide a redirect_to, it will assume a view with name create.html.erb or create.html.haml, etc. and try to render it giving you a missing template. The most common design is create redirects to @model and destroy redirects to index_path.Garrett Lancaster ------------------------------------------------------------------------ Mauro <mailto:[email protected]> January 11, 2011 3:58 PM Yes, you can omit respond_with. Most of my apps are entirely without respond_with calls unless I have an explicit need for xml, etc.If I omit respond_with in some actions like create and destroy raise an error of missing template.--You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.To post to this group, send email to [email protected].To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.------------------------------------------------------------------------ Garrett Lancaster <mailto:[email protected]> January 11, 2011 3:14 PMYes, you can omit respond_with. Most of my apps are entirely without respond_with calls unless I have an explicit need for xml, etc.------------------------------------------------------------------------ Mauro <mailto:[email protected]> January 11, 2011 3:02 PM If I don't want xml results but only html can I omit respond_with in some actions? For example index from: respond_with(@sectors = Sector.all) becomes only @sectors = Sector.all isn't it?
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
<<inline: compose-unknown-contact.jpg>>
<<inline: postbox-contact.jpg>>

