2012-01-20 51 views
0

我想在rails上做一個有條件的更新3.1 根據你來自的位置,更新後,重定向將完成。 將我的1大表單分割成單獨的小表單,所以現在想法是重定向到正確的子表單。更新後的條件重定向

例如,表格可從提交:

  • 輪廓基本形式
  • 查看資料形成

我能想出的檢查動作的名稱和使用的唯一的事情,重定向。但它的代碼非常醜陋,並且不能完全正常工作。這將是什麼樣的鐵路?

這是我的控制器更新動作:

def update 

    @profile = Profile.find(params[:id]) 

    respond_to do |format| 

    if @profile.update_attributes(params[:profile]) 
     format.html { redirect_to @profile, notice: 'Profile was successfully updated.' } 
     else 
     format.html { 
      render :action => "edit_basics" 
      # 

     } 
     end 
    end 
    end 

回答

4

爲什麼不只是通過重定向位置作爲形式的hidden_​​field,然後讓每個表單設置爲需要:

redirect_to params[:redirect_location] 

你可以如果您不想在HTML中公開原始字符串,也可以使用步驟或其他方法執行此操作:

redirect_to location_for_step(params[:step]) 
+0

in vie w '<%= hidden_​​field_tag:redirect_location,'/ whatever/url'%>' – maxcobmara