2011-03-16 85 views
0

我在我的控制器下面的代碼:Rails在編輯記錄和創建時發送事件?

# GET /kases/1/edit 
    def edit 
    @kase = Kase.find(params[:id]) 
    respond_to do |format| 
     format.html { render :layout => 'kaseshow'} # show.html.erb 
     format.xml { render :xml => @kase } 
     format.pdf { render :layout => false } 
    end 
    end 

    # POST /kases 
    # POST /kases.xml 
    def create 
    @company = Company.find(params[:kase][:company_id]) 
    @kase = @company.kases.new(params[:kase]) 

    if @kase.save 
     UserMailer.deliver_makeakase("[email protected]", "Highrise", @kase) if params[:sendtohighrise] 
     UserMailer.deliver_makeakaseteam("[email protected]", "Highrise", @kase) if params[:notify_team_of_creation] 
     @kase.create_freeagent_project(current_user) if params[:send_to_freeagent] 

     redirect_to(@kase) 

     #flash[:notice] = 'Case was successfully created.' 
     flash[:notice] = fading_flash_message("Case was successfully created.", 5) 
     else 
     render :new 
     end   
    end 

我試圖使它所以如果用戶編輯的情況下,然後選擇發送到希捷FreeAgent tickbox:

@kase.create_freeagent_project(current_user) if params[:send_to_freeagent] 

那麼情況對於Freeagent(在線會計軟件)感到不滿。我並不擔心重複處理,因爲如果情況已經存在於Freeagent中,那麼用戶不需要重新發送它。

這可能嗎?

回答

2

你的'更新'方法在哪裏?只有當您加載數據並呈現用戶將看到的編輯記錄的頁面時,纔會調用編輯。當在該頁面上單擊保存/更新/提交時,它應該調用控制器中的'update'方法。所以,你應該能夠把同樣的進線「更新」方法的,如果塊的真實狀況,看起來是這樣的:

if @kase.update_attributes(params[:kase]) 
    #your code would go here 
    @kase.create_freeagent_project(current_user) if params[:send_to_freeagent] 
    #the rest of the code would go here 
end 
0

它,您可以創建複選框/收音機/隱藏字段在你的編輯表單中。

如果您想爲Kase創建一些模型,那麼還可以查看accep_nested_attributes