attr_accessor :password, :password_confirmation and
attr_accessible :password, :password_confirmation
Who can tell me whats the difference
attr_accessor :password, :password_confirmation and
attr_accessible :password, :password_confirmation
Who can tell me whats the difference
attr_accessor is ruby method. It sets getter and setter. However, attr_accessible is a rails method that will allow to pass values in mass assignment.
For example-
attr_accessor :password, :password_confirmation
u = User.new({ :password => 'XXX', :password_confirmation => 'XXX' })
---
u.password => nil
u.password_confirmation => nil
But, you will be able to user getter and setter values in this case.
attr_accessor :password, :password_confirmation
u.password = 'XXX'
---
u.password => 'XXX'
On the other hand for attr_accessible -
attr_accessible :password, :password_confirmation
User.new({ :password => 'XXX', :password_confirmation => 'XXX' })
---
u.password => 'XXX'
u.password_confirmation => 'XXX'
attr-accessor
creates the getter
and setter
methods for the specified attributes
method.attribute
(getter)
method.attribute
= (setter)
attr_accessible
is from ActiveRecord::Base
and "Specifies a white list of model attributes that can be set via mass-assignment."