레일에서 루비를 배우고 있습니다. 나는 사용자 정보를 저장하기위한 모델을 만들고 rake db : seed을 호출하면 다음 오류가 발생합니다. 누락 된 부분이 있습니까?rake db : seed thorwing 보호 된 속성을 대량 지정할 수 없습니다.
rake db:seed
require 'digest'
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :email, :password
validates :email, :uniqueness => true,
:length => {:within => 5..50},
:presence => true
validates :password, :confirmation => true, :length => { :within => 4..20 }, :presence => true, :if => :password_required?
has_one :profile
has_many :articles, :order => 'published_at DESC, title ASC',
:dependent => :nullify
has_many :replies, :through => :articles, :source => :comments
before_save :encrypt_new_password
def self.authenticate(email, password)
user = find_by_email(email)
return user if user && user.authenticated?(password)
end
def authenticated?(password)
self.hashed_password == encrypt(password)
end
def encrypt_new_password
return if password.blank?
self.hashed_password = encrypt(password)
end
def password_required?
hashed_password.blank? || password.present?
end
def encrypt(string)
Digest::SHA2.hexdigest(string)
end
end
Can't mass-assign protected attributes: password_confrimation
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.2.3/lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/attribute_assignment.rb:75:in `assign_attributes'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/base.rb:498:in `initialize'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/persistence.rb:44:in `new'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/persistence.rb:44:in `create'
C:/Users/huzaifa.gain/My Documents/Aptana Studio 3 Workspace/blog/db/seeds.rb:6:in `<top (required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `block in load'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:23
@Gainster : 올바른 속성 이름을 사용할 수 있는지 확인하고 오타를 조심하십시오. –
Begining Rails 3을 따르고 있습니다. 필드를 만들지 않습니다. attr_accessible https://gist.github.com/326271 그래서 내가 왜 그들을 액세스 가능하게해야하는지 이해하지 못합니까 ?? – Gainster
사용중인 릴리스에 따라 Rails 3.2.3은 모든 모델을 기본적으로 보호하는 변경 사항을 가져 왔습니다. 자세한 내용은 릴리스 정보를 참조하십시오. http://weblog.rubyonrails.org/2012/3/30/ann-rails-3-2-3-has-been-released/ – simonmorley