开发者

where do I put the respond_to if there is an if-statement in the controller in rails?

开发者 https://www.devze.com 2023-01-03 03:36 出处:网络
I have a controller that has if-condition: def update @contact_email = C开发者_开发知识库ontactEmail.find(params[:id])

I have a controller that has if-condition:

  def update
    @contact_email = C开发者_开发知识库ontactEmail.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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消