我得到這個錯誤,當我登錄:需要幫助調試這個錯誤
NoMethodError in Videos#index
Showing /rubyprograms/dreamstill/app/views/videos/_video.html.erb where line #3 raised:
undefined method `value' for nil:NilClass
我不知道爲什麼我得到這個錯誤,因爲我的應用程序運行良好更早......這裏是_video.html.erb文件。第3行是什麼導致錯誤:
1: <%= div_for video do %>
2: <div class='voting_div'>
3: <%= link_to "⇑".html_safe, video_votes_path(:video_id => video.id, :type => "up"), :method => :post, :remote => true, :class => "up_arrow round #{current_user && current_user.votes_for(video).value == 1 ? 'voted' : 'unvoted' }" %>
4: <div id='vote_display' class = 'round'>
5: <p id='votes'>
6: <%= video.vote_sum %>
我該如何解決這個錯誤?你想要我發佈什麼樣的代碼,這樣可以解決這個問題?
哇!修復它!爲什麼你的代碼工作,爲什麼不工作? – 2011-03-26 05:21:55
您收到'votes_for'的零結果。我先拉票,然後調用'vote.value'只有當它不是零。 – mnelson 2011-03-26 05:28:14
好的,雖然我看不到它有什麼不同,但它是在做我所做的,但是在兩個步驟中,不知道爲什麼我會出現錯誤... – 2011-03-26 05:36:22