Я понимаю, что это немного новичок. Я пытаюсь определить метод unread_notices
и затем вызвать его для current_user
. Вот что у меня есть:
module ApplicationHelper
def unread_notices
Notice.where("read" => false)
end
def current_user
User.find(session[:user_id])
end
application.html.erb:
<li><%= link_to "Notices (#{current_user.unread_notices.count})", notices_path %></li>
unread_notices
работает, пока я не отфильтрую его с помощью current_user
, затем будет написано undefined method 'unread_notices' for #<User:0x110dd0f48>
. Какие-нибудь мысли? Спасибо.
UPDATE
class User < ActiveRecord::Base
has_many :notices, :dependent => :destroy
class Notice < ActiveRecord::Base
belongs_to :user