Open jpoday opened 12 years ago
a better solution from here : http://unhandledexpression.com/2011/06/28/rails-and-oauth-plugin-part-2-the-consumer/#comment-205
You should add this to your ApplicationController:
def current_user=(user) current_user = user end
I've tried that solution def current_user=(user) current_user = user end
and it works well when I am in Rails 3.0.7 but am still getting user_id=nil in 3.1. Anyone else encountered this?
It worked for me in 3.1. I had to delete some part of the code which was useless for me. I can't help more...
@yutai I haven't tested to see if anything < Rails 3.1 works but I am also having the same issue. Absolutely driving me nuts! I'm going to see if @jpoday is on the right track and edit the model directly... @keyzz Why is your solution better? What is happening there that is causing the user_id to be accessible?
@octopusinc, i've found some other craziness specifically to how the gem behaves in 3.1 i've outlined it here https://github.com/pelle/oauth-plugin/issues/96
No solutions in there, but thought you might find it interesting. Basically, as far as I can tell, the user_id is passed along to the gem all the way till it tries to save the token. funny thing is, if I try to save it again one line later in the same method, it works.
completely baffles me.
Thanks for sharing your research @yutai. I'm with you, baffling...
I had this in the ApplicationController (I don't know why I wrote that here):
def logged_in?
true
end
That wasn't working until I removed it ... and maybe another similar part.
@octopusinc : the solution I wrote is better because I don't have to change the code in the Gem. As I will put my app in production later, I can't change any line of the Gems...
In the ConsumerToken model I commented out:
#before_create :create_user
because of something I read over here (https://github.com/rails/rails/issues/1594) & IT WORKED. @pixeltrix says that the belongs_to
association triggers a before_save
too. Is this method nuking the user variable by creating a new one?
Hello all,
I'm not sure if this is specific to my use, but I found I had to add attr_accessible :user_id to the model.class_eval block in oauth/consumers/token.rb
Otherwise, the token were being saved without user ids.