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.

compose-unknown-contact.jpg

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 Lancaster

compose-unknown-contact.jpg

postbox-contact.jpg

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?

def create
    @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:
def create
    @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

compose-unknown-contact.jpg

postbox-contact.jpg

where did you get this information?

Google for respond_with:

Garrett Lancaster

compose-unknown-contact.jpg

postbox-contact.jpg

Didn’t know apidock.com.

Msan Msan wrote in post #974376: