simple_roles icon indicating copy to clipboard operation
simple_roles copied to clipboard

Cannot add role with symbol

Open MartinJNash opened this issue 10 years ago • 5 comments

When I try to add a role with a symbol, I get the following error.

ActiveRecord::AssociationTypeMismatch: Role(#70173822757240) expected, got Symbol(#70173818545420)
from /Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.1/lib/active_record/associations/association.rb:216:in `raise_on_type_mismatch!'
user.add_role :admin

Admin is a valid role

Role.pluck :name  # => ["user", "admin", "editor"]

MartinJNash avatar Jun 26 '14 06:06 MartinJNash

Here is the full stack trace

ActiveRecord::AssociationTypeMismatch: Role(#70173822757240) expected, got Symbol(#70173818545420)
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.1/lib/active_record/associations/association.rb:216:in `raise_on_type_mismatch!'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.1/lib/active_record/associations/collection_association.rb:356:in `block in replace'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.1/lib/active_record/associations/collection_association.rb:356:in `each'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.1/lib/active_record/associations/collection_association.rb:356:in `replace'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.1/lib/active_record/associations/collection_association.rb:41:in `writer'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.1/lib/active_record/associations/builder/association.rb:118:in `roles='
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/simple_roles-0.0.12/lib/simple_roles/many/roles_methods.rb:71:in `add_roles'
/Users/nash/dev/rails/ywk/db/seeds.rb:17:in `<top (required)>'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.1.1/lib/rails/engine.rb:543:in `load_seed'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.1/lib/active_record/tasks/database_tasks.rb:184:in `load_seed'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
/Users/nash/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'

MartinJNash avatar Jun 26 '14 06:06 MartinJNash

OMG, I somehow missed this your report @MartinJNash. I will investigate what can be an issue here though I believe this is might not be actual for you anymore.

Sorry for not reacting the moment when your reported this.

stanislaw avatar Aug 10 '14 12:08 stanislaw

+1 on this, having the same error in my seeds.rb.

troytc avatar Aug 18 '14 03:08 troytc

+1 when I upgraded rails from 4.1.0 to 4.1.4

gadikotamohan avatar Aug 18 '14 05:08 gadikotamohan

While I didn't have enough time to work on this, I welcome anyone who can come up with pull request. Thanks.

stanislaw avatar Aug 18 '14 16:08 stanislaw