Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentError - When assigning attributes, you must pass a hash as an argument.: #358

Closed
MichaelSp opened this issue Apr 10, 2014 · 3 comments

Comments

@MichaelSp
Copy link

On resource update I get this:

ArgumentError - When assigning attributes, you must pass a hash as an argument.:
  activerecord (4.1.0) lib/active_record/attribute_assignment.rb:16:in `assign_attributes'
  activerecord (4.1.0) lib/active_record/persistence.rb:231:in `block in update'
  activerecord (4.1.0) lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
  activerecord (4.1.0) lib/active_record/transactions.rb:208:in `transaction'
  activerecord (4.1.0) lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
  activerecord (4.1.0) lib/active_record/persistence.rb:230:in `update'
  inherited_resources (1.4.1) lib/inherited_resources/base_helpers.rb:85:in `update_resource'
  inherited_resources (1.4.1) lib/inherited_resources/actions.rb:45:in `update'
  app/controllers/posts_controller.rb:21:in `update'

My controller:

class PostsController < InheritedResources::Base
  #...
  def update
    update! do |format|
      format.html { render :index }
      format.json { respond_with_bip(@post) }
    end
  end
  #...
end

I tracked it down to this code:

def update_resource(object, attributes)
   object.update_attributes(*attributes)
end

If I remove the star object.update_attributes(attributes) everything is fine. I don't understand what's wrong here? Is this a bug? Am I using it wrong?
Anyone else getting this?

@peterhoeg
Copy link

@MichaelSp I'm seeing this too. Did you figure out what was going on?

@MichaelSp
Copy link
Author

I still have no idea. But I have a work-around. Add this to your (Application-) Controller:

def update_resource(object, attributes)
   object.update_attributes(attributes)
end

@peterhoeg
Copy link

Ah, the fix is to rename the resource_parms method to permitted_parms make it return a hash instead. Check this out: #236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants