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

Methods dissapear #3

Open
mattiassvedhem opened this issue Nov 21, 2011 · 6 comments
Open

Methods dissapear #3

mattiassvedhem opened this issue Nov 21, 2011 · 6 comments

Comments

@mattiassvedhem
Copy link

I'm having trouble locating this error. Example:

In rails console.

User.last.has_role?

Works.

If I change anything in my code however

User.last.has_role?
NoMethodError: undefined method `has_role?' for #User:0x007fcd17d508b8

And I need to restart the console/server

Any Ideas on where to look? I figure it has something to do with the caching?

@kristianmandrup
Copy link
Owner

"If I change anything in my code however" is to vague for me to have an idea of what it could be.
You are welcome to post your project on github somehow, either as a repo or as a Gist and I will take a look.

@mattiassvedhem
Copy link
Author

Sorry for being vague.

What I meant was that if I change anything in my rails code. i.e in my models. Or add permits to cantango for example.

I have troles set up with a string_many association. And trying to use the method in my controller / console, that's pretty much it.

Anyway, here's the trace

irb(main):038:0> User.first.has_role? :admin
  User Load (20.3ms)  SELECT `users`.* FROM `users` LIMIT 1
NoMethodError: undefined method `has_role?' for #<User:0x007fd36727f1e0>
    from /Users/speggey/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activemodel-3.1.1/lib/active_model/attribute_methods.rb:385:in `method_missing'
    from /Users/speggey/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/attribute_methods.rb:60:in `method_missing'
    from (irb):38
    from /Users/speggey/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
    from /Users/speggey/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
    from /Users/speggey/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

The method worked and returned true, then I changed a permit from can to cannot. If I restart the console the method will be defined.

@kristianmandrup
Copy link
Owner

I recommend that you try one of the other roles solutions compatible with cantango. Try simple_roles or roles_active_record instead for now. I need some more work on troles to make sure plays nice.

In rails console, did you try to use the reload! command after making your changes!?

@mattiassvedhem
Copy link
Author

I did use reload!
Ran the specs but couldn't find the issue. I will let you know if I find it.

Thanks!

@kristianmandrup
Copy link
Owner

For now, please try out: https://github.com/stanislaw/simple_roles
If you have any problems/questions, ask @stanislaw

Also try out the latest patch release of CanTango (v. 0.9.4.5)

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

2 participants