4
這是如此簡單,以至於我無法找到任何有關此文檔的任何信息,包括API文檔和Rails源代碼:什麼是Rails關聯的更新方法?
我有:belongs_to關聯,並且我已經瞭解了您調用的正常模型方法在控制器中,當你沒有關聯時與你做的時候稍有不同。
例如,我有我的協會建立控制器動作做工精細:
@user = current_user
@building = Building.new(params[:building])
respond_to do |format|
if @user.buildings.create(params[:building])
# et cetera
,但我不能找到文檔更新是如何工作的:
@user = current_user
@building = @user.buildings.find(params[:id])
respond_to do |format|
if @user.buildings.update(params[:building])
# et cetera
使用更新方法給出的錯誤「參數的錯誤數量(1 for 2)」,我無法弄清楚應該發送什麼參數。
這就是它!我已經嘗試過那個,但是使用了錯誤的對象。謝謝。 – user478798 2010-12-05 17:45:06