Can I omit respond_with

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?

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.

On 11 January 2011 22:14, Garrett L.
[email protected]wrote:

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.

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.

Garrett L.

On 11 January 2011 23:02, Garrett L.
[email protected]wrote:

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?

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 L.

On 11 January 2011 23:45, Garrett L.
[email protected]wrote:

end

It’s just built into the method.

where did you get this information?

Google for respond_with:
http://apidock.com/rails/ActionController/MimeResponds/respond_with

Garrett L.

On 12 January 2011 17:34, Garrett L.
[email protected]wrote:

Google for respond_with:
http://apidock.com/rails/ActionController/MimeResponds/respond_with

Didn’t know apidock.com.

Msan M. wrote in post #974376:

On 12 January 2011 17:34, Garrett L.
[email protected]wrote:

Google for respond_with:
http://apidock.com/rails/ActionController/MimeResponds/respond_with

Didn’t know apidock.com.

I find http://www.railsapi.com a lot more attractive, but APIdock has a
couple of cool features.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]