Devise - current_user nil on post request?

Up vote 0 down vote favorite share g+ share fb share tw.

I know I had this working before, but for some reason the current_user method call in one of my create actions keeps returning nil. It works fine when used in other controller and so forth, such as a side panel to show my username. Class CombatInstancesController current_user.

Create_combat_instance end def update @combat_instance = current_user. Combat_instance @combat_instance. Trigger_actions(params:actions) @combat_instance.

Perform_ai_actions @combat_instance. Save # should we instead call this in an after hook? Render :json => @combat_instance end end The line CombatInstance.

Find(current_user. Combat_instance. Id).

Destroy if current_user. Combat_instance is where current_user returns nil. The workflow is: I go to the home page, I login just fine.

I can see my username at the top, which is generated using the current_user helper in the view. However, when I submit a form that hits the create action here, it returns nil. Ruby-on-rails devise link|improve this question edited Aug 15 '11 at 2:31 asked Aug 15 '11 at 1:04agmcleod1,362238 91% accept rate.

I'm not sure this is enough to go on. Can you provide more details? In what line are you getting the nil?

What is the exact error/behavior you are experiencing? – Brandon Tilley Aug 15 '11 at 1:27 Updated my question. Thanks – agmcleod Aug 15 '11 at 2:31 1 If you refresh the home page after logging in, are you still logged in?

What do you get on the log if you do a RAILS_DEFAULT_LOGGER. Info current_user (Rails 2) or Rails.logger. Info current_user (Rails 3) from within the very top of the create action?

Do you have any before_filters in the CombatInstancesController or the ApplicationController that may be causing oddness? – Brandon Tilley Aug 15 '11 at 2:41 Yes I am still logged in. When I output current_user at the top of the create action to the log file, it just outputs an empty string.

– agmcleod Aug 15 '11 at 12:50.

Yes to both of those things. The post is made with an ajax call, and I do have the csrf_meta_tag in the head section. – agmcleod Aug 15 '11 at 12:48 whats your code for loading "current_user" – Stephen Aug 15 '11 at 15:10 Not sure what you mean.

The helper is built-in to devise itself, so it's not my own defined method. As I stated in my question, the helper works fine in the views and so forth. It also seems to when I put it in another controller action.

– agmcleod Aug 15 '11 at 15:24 So it looks like the token was not being passed in the ajax call. I simply added it manually to the headers, and it works: gist.github.com/1149539. Can see the before and after files there.

– agmcleod Aug 15 '11 at 16:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions