-1
attr_accessor :password, :password_confirmation and
attr_accessible :password, :password_confirmation 

Who can tell me whats the difference

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
super_fish
  • 107
  • 1
  • 3

2 Answers2

0

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'
0

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."

Veeru
  • 348
  • 4
  • 13