The main difference between attr_accessible and attr_accessor is that attr_accessible is a Rails method that basically specifies a white list of model attributes that can be set via mass-assignment and on the other hand attr_accessor is a ruby method that creates getter/setter for the variable
Example of attr_accessor:
class Car
attr_accessor :name
end
car = Car.new
car.name = "BMW"
car.name # => "BMW"
Example of attr_accessible:
This is mass assignment:
Message.new(params[:message])
Basically assigning all the attributes to the an instance based on the params[:message] hash.
0 Comment(s)