This project is archived and is in readonly mode.
HABTM relation & update_attributes
-
Cesario
Hi Phil,
I can't reproduce this behavior locally. Do you have specific validation method somewhere that could be interesting to look at? -
Cesario
- Tag set to activerecord 3.0, 3.0
-
Philippe Lang
Hi Cesario,
The only thing I did not mention is that the users table has been generated by devise. The model looks like this:
class User < ActiveRecord::Base has_and_belongs_to_many :roles has_many :mailings # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, :lockable and :timeoutable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me def is?(role) self.roles.where(:name => role).exists? end endI'll try disabling a few options, and maybe it will start working again...
Philippe
-
Philippe Lang
Sorry, this was my mistake. I had to add :role_ids in the list of accessible attributes and now it works great.
attr_accessible :email, :password, :password_confirmation, :remember_me, :role_idsIs there a way of getting an error in such a case? When the :role_ids attribute is not accessible, update_attributes fails without saying anything...
-
Aditya Sanghi
- State changed from new to invalid
- Importance changed from to Low
Have a look in the logs, mass assigning protected attributes throws a warning message in development mode i believe.
Marking ticket as invalid.