On May 5, 3:02 pm, overlap <[email protected]> wrote:
> Hi there!
>
> % rails c
> Loading development environment (Rails 3.2.3)
> irb(main):001:0> Project.all
> Project Load (0.1ms) SELECT "projects".* FROM "projects"
> => [#<Project id: 1, name: "test", file: "fff", created_at:
> "2012-05-05 13:05:44", updated_at: "2012-05-05 13:05:44">]
> irb(main):008:0> a = Auction.new(:name => "foo", :begin =>
> nil, :project_id => 1)
> => #<Auction id: nil, name: "foo", begin: nil, project_id: 1,
> created_at: nil, updated_at: nil>
> irb(main):009:0> a.save()
> => true
>
> % rails s
>
> 1 => trying to add an auction using the front
> end:http://dl.dropbox.com/u/8724298/Screen%20Shot%202012-05-05%20at%203.4...
> 2 => I receive another error:
> ActiveModel::MassAssignmentSecurity::Error in
> AuctionsController#create
>
> Can't mass-assign protected attributes: project
> Rails.root: /private/tmp/testapp
>
Well you skipped over the code that raises the error, but I'm guessing
you load the project from the database and do something like
Auction.new(:project => p)
If so then you need to add :project to your attr_accessible list. The
prefix attr_ sort of implies that everything on the list has to be an
attribute, but that's not so. Any key that you want to be allowed when
calling new,create etc. should be on the list (and before you add it
to the list, take a minute to think about the consequences of the user
being able to set arbitrary value)
Fred
> Application Trace | Framework Trace | Full Trace
> app/controllers/auctions_controller.rb:43:in `new'
> app/controllers/auctions_controller.rb:43:in `create'
> Request
>
> Parameters:
>
> {"utf8"=>"✓",
> "authenticity_token"=>"0gcU4dbRGsgmiXGEcMKO1o1Oec6GoGQ4OziwNbRyfoc=",
> "auction"=>{"name"=>"FFF",
> "begin(1i)"=>"2012",
> "begin(2i)"=>"5",
> "begin(3i)"=>"5",
> "begin(4i)"=>"13",
> "begin(5i)"=>"44",
> "project"=>"1"},
> "commit"=>"Create Auction"}
>
> [http://dl.dropbox.com/u/8724298/Screen%20Shot%202012-05-05%20at%203.4...
> ]
>
> Where am I wrong?
>
> Thank you!
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.