Skip to content

Loading…

Error when creating record in 1.0.5 #28

Closed
martinstannard opened this Issue · 1 comment

2 participants

@martinstannard

I have a model that is instantiated using first_or_create:

def session_api_key
api_keys.active.session.first_or_create()
end

Upgrading from 1.0.3 to 1.0.5 produces the error below:

ArgumentError: wrong number of arguments (2 for 0..1)
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/core.rb:180:in initialize'
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in
new'
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in new'
from /Users/martin/.gem/ruby/2.0.0/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/persistence.rb:45:in
create'
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/relation.rb:121:in block in create'
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/relation.rb:270:in
scoping'
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/relation.rb:121:in create'
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/relation.rb:133:in
first_or_create'
from /Users/martin/code/brightseeds/app/models/user.rb:39:in session_api_key'
from (irb):17
from /Users/martin/.gem/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in
start'
from /Users/martin/.gem/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in start'
from /Users/martin/.gem/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:64:in
'
from ./script/rails:6:in require'
from ./script/rails:6:in

'

This can also be triggered by a simple create in the console:

irb(main):008:0> ApiKey.create
ArgumentError: wrong number of arguments (2 for 0..1)
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/core.rb:180:in initialize'
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in
new'
from /Users/martin/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in new'
from /Users/martin/.gem/ruby/2.0.0/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/persistence.rb:45:in
create'
from (irb):8
from /Users/martin/.gem/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in start'
from /Users/martin/.gem/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in
start'
from /Users/martin/.gem/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:64:in <top (required)>'
from ./script/rails:6:in
require'
from ./script/rails:6:in `

'

@rafaelfranca
Ruby on Rails member

This is because protected_attributes 1.0.5 only works with Rails >= 4.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.