(undefined method `vote_exclusively_for' for nil:NilClass) when user is logged out, but not when logged in - Rails 3 (thumbs_up gem)?

It seems to me that both current_user and @client_user are nil.

It seems to me that both current_user and @client_user are nil. @client_user is never defined because method check_token_or_user is called only on action :compare, not your actions :vote_up or :vote_down About current_user - it depends on how your authentication is implemented but I'd say that if authenticate_user! Is not called, it will be nil as well.

And authenticate_user! Is definitely not called, because of the :except => :vote_up, :vote_down in the before_filter. EDIT: So to solve this you have to add more actions to one of those before_filters so one of them could actually get called.

What if I told you, the action that the is being rendered - i.e. Where the uploads are that can be voted on, is being called. Would that change your answer?

As in, the url is stages/46/compare? P1=jsugkjeb where a before_filter exists for that specific action like so: before_filter :check_token_or_user, :only => :compare So, the assumption basically is that since they are already on the compare action (as that is the only action where voting is allowed) the @client_user should be initialized and not be nil. Also, I added a debug(@client_user) and see that @client_user!

= Nil – marcamillion May 10 at 6:54 For instance, this is the output of my debug(@client_user) ---! Ruby/object:Client attributes: id: 62 email: test@abc. Com user_id: 1 created_at: 2011-04-06 10:14:12.002169 updated_at: 2011-04-06 10:14:12.002169 authentication_token: rRC58oHa48WZlZFO2Fr_ attributes_cache: {} Which is right.

– marcamillion May 10 at 6:55 Mate, the error message you showed us clearly says that (current_user || @client_user) is nil, because you got message: undefined method `vote_exclusively_for' for nil:NilClass. Then both current_user and @client_user has to be nil. Make sure you placed the debug command at the right place so that the vote_up action gets called.

Note that it does not matter what you render, the "current action" is the method that gets called in the controller whatever you render in it. – Jan Minárik May 10 at 7:14 Interesting....ok, will move the debug command. – marcamillion May 10 at 7:26 Ok...thanks...your response helped me narrow it down and get it.

I eventually had to write a new before_filter but you definitely helped me narrow it down. – marcamillion May 10 at 8:27.

Related Questions