1

I have the following method in my User model.

def self.create_from(house:)
  create!(
    house: house,
    uuid: generate_uuid,
  )
end

Why am I getting a ActiveModel::MassAssignmentSecurity::Error for both house and uuid if I am not calling create_from from a controller? What is the suggested way to solve this in Rails 4.2? I am used to use strong_params when calling from a Controller, but this model method is called not from a controller.

Hommer Smith
  • 26,772
  • 56
  • 167
  • 296

1 Answers1

0

You certainly have enabled mass assignment protection (with config.active_record.whitelist_attributes = true in your config file), so you need to explicitly indicate which attributes can be updated by methods like update_attributes. You do it with attr_accessible.

In the models, use attr_accessible

See questions related to attr_accessor and attr_accessible for further informations here, here or here

Credit: Active Model MassAssignmentSecurity Error

Community
  • 1
  • 1
svelandiag
  • 4,231
  • 1
  • 36
  • 72