I have just started coding with rails. I am using: Rails 3.2.8 ruby 1.9.3p194
I created a migration and a corresponding model, all inside the files they should be ( I present them all together for conciseness):
class CreateMovies < ActiveRecord::Migration
def up
create_table 'movies' do |t|
t.string 'title'
t.timestamps
end
end
def down
drop_table 'movies'
end
end
class Movie < ActiveRecord::Base
end
So, I would like to enter the 'rails console' and play around with the data base as a learning process.
This is what I enter and the error message I got:
1.9.3p194 :021 > k = Movie.new(:title => 'coco')
ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: title
I have to say that the above statement works fine if I append :without_protection => true.
I looked up about mass-assignment and I understood that this is something we should be very careful about. BUT, it appears that rails activated mass-assignment protection by default. In my case I would like to create entries using hashes and this is extremely useful for debugging and learning!
Is there a way to de-activate this kind of protection? I would like to have public attributes by default! How can I achieve that ?
It is weird that, in my web research, I concluded that this feature is not there by default i.e. ActiveModel does not create protected attributes by default. (http://stackoverflow.com/questions/3764899/is-there-a-way-to-make-rails-activerecord-attributes-private) But in my case all attributes are private !
In my code, in the future, should I try to assign all attributes individually? This will be tedious. Is there a better way to have both security and avoid this tedious process ?
Thank you in advance from the depths of my heart!