How you do this does not interfere with "mass assignment."
Bulk assignment is a term used when Rails processes attribute assignments in a model. This is usually done in the controller using the names and values in params .
When you do the assignment of yourself, it is also a “mass assignment”, in some way; but you have great control over what to appoint and what not in this case. Thus, in order to maintain a record of the code for the template code, Rails provides attr_accesible - the same control, less code.
To find out how it is used:
Suppose the ActivityLog model has the user_ip_address attribute.
user_ip_address is now an attribute in the model and can be assigned by mass assignment or "self-expanded mass assignment".
But in both cases this is not true - you do not want user input to set a value for this attribute.
Instead, you want to always find out the actual IP address of the user and assign it (ignoring any value in params ). That way you would exclude user_ip_address from attr_accessible and instead assign it yourself.
attr_accessible :all_attributes_except_user_ip_address @al = ActivityLog.new(params[:model_object_params]) @al.user_ip_address = get_origin_user_ip_address @al.save
For any information that the user cannot change, use attr_accessible and remove it from the list.
source share