에서 attr_accessor 및 attr_accessible에 대한 혼란이 모두 간단한 가입 신청레일
schema.rb
create_table "users", :force => true do |t|
t.string "email"
t.string "password_hash"
t.string "password_salt"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
User.rb
attr_accessible :email, :password, :password_confirmation
attr_accessor :password
before_save :encrypt_password
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
.
.
.
왜 사용하는 암호가 attr_accessible 및 attr_accessor입니까? 난 attr_accessor 제거하면
은 : 암호 레일 콘솔에서 실행시, 오류가 발생했습니다 :
user = User.new
user.password # => no method error
을하지만 실행할 때 :
user = User.new
user.email # => nil
작업 user.email 의미 attr_accessor에 추가하지 않고, 왜? !!
및이가 작동 :
user = User.new
user.password_confirmation # => nil
을하지만 난 제거 할 때
validates_confirmation_of :password
가 작동하지 않습니다, 왜?.
(http://blog.mhartl.com/2008/09/21/mass-assignment-in-rails-applications/) [GitHub hack] (http://www.extremetech.com/computing/)에 허용 된 문제 120981- 해킹 - 해킹 - 수백만 건의 프로젝트 - 올해 - 수정 또는 삭제 위험에 처해 있음). –
위대한, 그러나 당신은 대량 할당으로 무엇을 의미 했느냐? –
"한 번에 하나씩"이동하지 않고 전체 속성 배열을 전달하는 지정. 예를 들어, 위의 예제에서 link-to의 예에서'@ user.update_attributes (params [: user])'를 사용합니다. 'attr_accessible'은 "괜찮습니다"라고 말하고, attr_accessible에 의해 언급되지 않은 것은 명시 적으로 개별적으로 업데이트 될 필요가 있다고 가정합니다. –