我对rails很新,我正在尝试创建用户登录.我浏览了这里的教程.最后它让我为质量分配添加"attr_accessible".但是,当我这样做时,我收到以下错误:
undefined method `attr_accessible' for #<Class:0x007ff70f276010>
Run Code Online (Sandbox Code Playgroud)
我在这篇文章中看到我需要<ActiveRecord :: Base.但我确实包含了这一点.这是我的用户模型的代码:
class User < ActiveRecord::Base
attr_accessor :password
EMAIL_REGEX = /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\z/i
validates :username, :presence => true, :uniqueness => true, :length => { :in => 3..20 }
validates :email, :presence => true, :uniqueness => true, :format => EMAIL_REGEX
validates :password, :confirmation => true #password_confirmation attr
validates_length_of :password, :in => 6..20, :on => :create
before_save :encrypt_password
after_save :clear_password
attr_accessible :username, :email, :password, :password_confirmation
def encrypt_password
if password.present?
self.salt = BCrypt::Engine.generate_salt
self.encrypted_password= …Run Code Online (Sandbox Code Playgroud)