0

Hi I do a simple model creation in the console in my development environment and everything works works fine however, in heroku I get a:

*: Can't mass-assign protected attributes: name, price, numobjects* 

I see in the heroku logs that it inserts nil values.

My command is:

 Plan.create!(:name => "Max", :price => 3, :numobjects => 50)

This worked fine in my local sqlite environment but not in heroku and postgres

Ayrad
  • 3,996
  • 8
  • 45
  • 86

2 Answers2

1

Normally if you create an object the way you do, mass assignment protection is checked, and as such, you should have these attributes accessible.

If, however, the only place you're creating this object is from the console, or from within a database seed, I would not make them accessible, but rather use

Plan.create!(:name => "Max", :price => 3, :numobjects => 50, :without_protection => true)

This way you overrule, just once, the checks rails normally does, which, in a controlled environment as your command shell, or database seeds, is fine.

Danny
  • 5,945
  • 4
  • 32
  • 52
0

here is the answer.

Mass Assignment usually means passing attributes into the call that creates an object as part of an attributes hash. That is, you pass a bunch of attributes in a hash into the call that creates the new object.

Community
  • 1
  • 1
Abolfazl Mahmoodi
  • 380
  • 1
  • 3
  • 20