我得到這個錯誤:如何解決「NoMethodError」異常?
NoMethodError in Videos#index
Showing /rubyprograms/dreamstill/app/views/videos/index.html.erb where line #12 raised:
undefined method `upvoted_videos' for nil:NilClass
Extracted source (around line #12):
9: <div class="home_options">
10: <ul class="home_options_list">
11: <li> <%= link_to "Top Songs", videos_path, :class => "top_songs chosen_home_option" %> </li>
12: <li> <%= link_to "#{pluralize(current_user.upvoted_videos.count, 'Upvoted Song')}", upvoted_videos_path, :action => "upvoted_songs", :class => "upvoted_songs" %> </li>
這是我的用戶模型:
def upvoted_videos
self.voted_videos.where("value = 1")
end
ahh你是對的...這是因爲我沒有登錄-_- – 2011-04-12 17:22:25
它碰巧發生在我們身上:) – 2011-04-12 17:23:57
哈哈這一個似乎總是讓我... – 2011-04-12 17:25:27