2016-01-20 33 views
1

當我寫我的投票程序,我是得到一個錯誤:
http://screenshot.sh/m3eeke1da49kLRails的ActiveModel無法訪問的值?

於是,我就發表評論代碼和檢查值。 http://screenshot.sh/mGR8cOuGizBRx

爲什麼我無法訪問值?有輔助方法的代碼:

def poll_option(poll) 
    @option = VoteOption.find_by(poll_id: poll.id) 
    content_tag :div, class: 'form-group' do 
     content_tag(:label) do 
      unless current_user.voted_for?(poll) 
      radio_button_tag 'vote_option[id]', @option.id 
      end 
     @option.title 
     end 
     visualize_votes_for @option 
    end 
    @option.inspect 
    end 
+0

你應該使用'bybug'或'pry'來調試這個問題,看起來你在這裏錯過了一些東西。 –

+0

你提供的代碼似乎並不一樣,這是拋出錯誤。無論如何,這可能是由於你循環一個數組而導致的,並且恰好存在一個零/空元素。 –

+0

好的我解決了問題,但代碼 – inshi666

回答

1

確定我解決了問題,但代碼 def poll_option(poll) @option = VoteOption.find_by(poll_id: poll.id) @option.each do |o| content_tag :div, class: 'form-group' do content_tag(:label) do unless current_user.voted_for?(poll) radio_button_tag 'vote_option[id]', o.id end o.title end visualize_votes_for o end end

end 給出了一個錯誤,「每」是未定義的方法。