2014-03-26 3 views
1

내 Rails 앱에서 작동하는 Wicked Wizard 보석을 얻으려고합니다. 응용 프로그램 (고안를 사용)에 대한 사용자 등록되면, 그들은이 형태로 리디렉션하고 있습니다 :배열에 대한 정의되지 않은 메소드`update '

:

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 %> 

나는 wizard_path을 처리 finances_welcome_controller.rb라는 컨트롤러를 생성

: 나는 submit 버튼을 클릭하면
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 

것은,이 오류를 받고 있어요3210

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 

내 리소스 모델에서 사용하는 구문과 동일하므로 업데이트 방법이 정의되지 않은 이유를 잘 모릅니다. Wicked Wizard gem이 this app에 성공적으로 구현되었습니다.

답변

1

시작하는 메소드 find_all_by은 단일 레코드뿐만 아니라 활성 레코드 인스턴스의 배열을 반환합니다. update은 단일 인스턴스에서만 작동합니다.

그래서 어느 당신은 each를 사용하여 ... 배열의 모든 인스턴스를 실행하려면 - 또는 당신은 단지에 의해 발견하는 경우 find_by 대신

find_all_by의를 사용하여 첫 번째를 가져 오려는 이 양식 제출 오류를 해결 한 것 같다,하지만 불행히도 데이터가 실제로 저장되지 않는다 - 응답을

@finance = Finance.find_by_user_id current_user[:id] 
@finance.update_attributes(params[:finance]) 
+0

감사 : ID가 ... 난 그렇게 find_by 로 변경 권 해드립니다. 내 사용자가 재무와 관련되어 있고 Finance를 편집하기 위해 _form을 눌렀을 때 마법사에서 제출 된 데이터로 데이터가 업데이트되지 않습니다. – beaconhill

+0

@beaconhill - 'update_attributes'를 시도하십시오. 또는 이상적으로는 @finance.assign_attributes (params [: finance]); finance.save!' – BroiSatse

+0

실제 재정 편집 페이지 (/ finance/6/edit)에있을 때 마법사 페이지 (/ finance_welcome/양식의 일부인 소득)로 돌아갈 때 절약됩니다 – beaconhill

관련 문제