5

I have a controller that has if-condition:

  def update
    @contact_email = ContactEmail.find(params[:id])

    if @contact_email.update_attributes(params[:contact_email])
      flash[:notice] = "Successfully updated contact email."
      redirect_to @contact_email
    else
      render :action => 'edit'
    end
  end

Where do I put the respond_to block:

respond_to do |format| 
  format.html {}
  format.json {render :json =>@contact_email}
end
Paweł Gościcki
  • 9,066
  • 5
  • 70
  • 81
Satchel
  • 16,414
  • 23
  • 106
  • 192

1 Answers1

9
def update
  @contact_email = ContactEmail.find(params[:id])
  ok = @contact_email.update_attributes(params[:contact_email])

  respond_to do |format| 
    format.html {
      if ok
        flash[:notice] = "Successfully updated contact email."
        redirect_to @contact_email
      else
        render :action => 'edit'
      end
    }
    format.json {
      if ok
        render :json =>@contact_email
      else
        ...
      end
    }
  end
end
zed_0xff
  • 32,417
  • 7
  • 53
  • 72