1
我試圖讓我的Rails應用程序中的邪惡嚮導gem工作。一旦該應用(使用設計)的用戶寄存器,他們重定向到這種形式:陣列的未定義方法`更新'
income.html.erb
<%= form_for @finance, url: wizard_path, :method => :put do |f| %>
<div class="field">
What <strong>year</strong> were you born?<br>
<%= f.number_field :age %>
</div>
<div class="field">
What's your <strong>zip code</strong>?<br>
<%= f.number_field :zip %>
</div>
<%= f.submit %>
<% end %>
我生成一個稱爲finances_welcome_controller.rb
控制器,其處理wizard_path
:
class FinancesWelcomeController < ApplicationController
before_filter :authenticate_user!
include Wicked::Wizard
steps :income, :expenses
def show
@finance = Finance.find_all_by_user_id current_user[:id] || @finance = current_user.finances.build(finance_params)
render_wizard
end
def update
@finance = Finance.find_all_by_user_id current_user[:id]
@finance.update(params[:finance])
render_wizard @finance
end
當我點擊submit
按鈕,我得到這個錯誤:
NoMethodError in FinancesWelcomeController#update
undefined method `update' for #<Array:0x00000104c6ff48>
Extracted source (around line #14):
def update
@finance = Finance.find_all_by_user_id current_user[:id]
**@finance.update(params[:finance])**
render_wizard @finance
end
不確定爲什麼沒有定義更新方法,因爲這與我的資源模型使用的語法相同。邪惡精靈寶石成功實施this app。
感謝您的答覆 - 這似乎已經解決了這一表單提交錯誤,但不幸的是數據不實際保存。我有我的用戶與財務相關聯,並且當我用我的_form編輯財務時,數據不會更新從嚮導提交的內容。 – beaconhill
@beaconhill - 嘗試'update_attributes'。或理想情況下'@ finance.assign_attributes(params [:finance]); ' – BroiSatse
當我回到嚮導頁面(/ finance_welcome /收入具有部分表格)時,它會保存,但當我在實際的金融編輯頁面時(/ finance/6/edit) – beaconhill