我正在使用带有rails的Devise,我想添加一个方法“getAllComments”,所以我写这个:
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable,:encryptable,:confirmable,:lockable,:timeoutable and :omniauthable devise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable # Setup accessible (or protected) attributes for your model attr_accessible :email,:password,:password_confirmation,:remember_me,:city,:newsletter_register,:birthday,:postal_code,:address_complement,:address,:lastname,:firstname,:civility has_many :hotels_comments class << self # Class methods def getAllComments true end end end
在我的控制器中:
def dashboard @user = current_user @comments = @user.getAllComments(); end
当我去我的网址时,我得到了
undefined method `getAllComments' for #<User:0x00000008759718>
我做错了什么?
谢谢