Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8203537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:35:29+00:00 2026-06-07T07:35:29+00:00

Rails 3.2.5, Devise 2.1 Using Devise to authenticate Users, and am having a problem

  • 0

Rails 3.2.5, Devise 2.1

Using Devise to authenticate Users, and am having a problem when creating a new user.

A user belongs to an Account which I create using a before_save filter in the User model. This works fine and has for a while.

New code requires the user’s account information as part of the create method. I rely on a parameter passed in the request, so this is not a good candidate for Model logic. I have overridden the Devise::RegistrationsController#create method:

class DeviseCustom::RegistrationsController < Devise::RegistrationsController
  def create
    super                                  # Call Devise's create
    account = current_user.account         # FAIL! (current_user is nil)
    account.partner_id = current_partner
    account.save!
  end
end

current_user is nil which causes the code to fail. Even in the case of a failure, I can see that the user and account records are being saved in the database — the logs show the commit, and logging self.inspect shows all my context (params, and much more) is all still present.

I would have thought that current_user would be available in this context — what’s an appropriate way to get at the user I have just created?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:35:32+00:00Added an answer on June 7, 2026 at 7:35 am

    Preface: I’ve never used devise.

    My guess is the current_user object hasn’t been created, either because there wasn’t a reason to (no user credentials) earlier on in the call chain, or because it hasn’t yet happend perhaps in #after_save (if that exists?).

    Devise uses a #resource method to grab the current instance variable you’re trying to save (or so it looks):

    https://github.com/plataformatec/devise/blob/master/app/controllers/devise_controller.rb#L16

    What I would do is change the it to:

    class DeviseCustom::RegistrationsController < Devise::RegistrationsController
        def create
          super                                  # Call Devise's create
          account = resource.account         # FAIL! (current_user is nil)
          account.partner_id = resource.current_partner
          account.save!
        end
    end
    

    You’ll probably want to add this to your model:

    attr_accessor :current_partner
    

    which will allow you to access the current_partner from the resource (model).

    Hopefully that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Rails 3 and Devise to create an app where users arrive
I have a rails application, and I authenticate users to the application using Devise.
Using Rails 3.1.3 with Devise 1.5.3. My app has accounts and users. Each account
I am using Devise in Rails to help authenticate users. I am trying to
I am using Devise to authenticate users in my rails app. I have couple
I have a Rails application for which I use devise to authenticate my users
So I am using Devise for user authentication in my rails app. I have
We have a web app running on Rails, using Devise and OmniAuth for user
I'm using Rails, iOS, and devise. I want to read a single user. The
In a Rails 3.2 app I have two user models set up using Devise:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.