So, here's my problem. I currently am building a simple authentication system for a rails site. I have 3 classes for this: Person, Session, and Role. In my Person model I have defined method_missing
to dynamically capture roles according to this guide.
In my application_controller I have some logic to deal with logins and log-outs, the result of which gives me the currently logged in user via:
@user = @application_session.person
Where @application_session
is the current session
Now in one of my controllers, I don't want anyone to be able to do anything unless they are an admin, so I included:
before_filter @user.is_an_admin?
This raises a NoMethodError
, even though I have method_missing
defined in my model. I tried defining is_an_admin?
, having it always return true as a test, and that works.
According to this question, I think the problem might have something to do with proxy associations. When I run:
puts @user.proxy_owner
I get a session object, since each user (Person) can have many sessions, and I got my user (Person) from the current session.
I am very confused why @user.is_an_admin?
is not calling the method_missing method in my Person controller. Please let me know if you need more information or code snippets.
I am using Rails 3 on Ruby 1.9