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

  • SEARCH
  • Home
  • 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 8287981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:10:57+00:00 2026-06-08T12:10:57+00:00

How do I create extra records when a user creates an account with devise?

  • 0

How do I create extra records when a user creates an account with devise?

Using a HABTM association between a User and Team model, I’m trying create a team that the user is associated with on there account creation.

Below is the code that I have attempted to use.

class RegistrationsController < Devise::RegistrationsController
  def create
    super
    current_user.teams.create(:name => 'User Name')
  end
end

I have also tried this

class RegistrationsController < Devise::RegistrationsController
def create

    build_resource

        if resource.save
        resource.teams.create(:name => 'User Name')
        if resource.active_for_authentication?
            set_flash_message :notice, :signed_up if is_navigational_format?
            sign_in(resource_name, resource)
            respond_with resource, :location => after_sign_up_path_for(resource)
        else
            set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
            expire_session_data_after_sign_in!
            respond_with resource, :location => after_inactive_sign_up_path_for(resource)
        end
        else
        clean_up_passwords resource
        respond_with resource
        end
    end
end
  • 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-08T12:10:58+00:00Added an answer on June 8, 2026 at 12:10 pm

    You can use a before_save in your model like this :

    class User < ActiveRecord::Base
      # ... your code ...
      after_create :set_user_on_team
      # ... your code ...
      private
        def set_user_on_team
          teams.create(:name => username)
        end
    end
    

    See the doc here : http://guides.rubyonrails.org/active_record_validations_callbacks.html#available-callbacks

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

Sidebar

Related Questions

I've been trying to create an app that records and uploads a video to
I'm trying to create a context menu which will be able to add extra
DI creates an extra layer of abstraction so that if your implementation class ever
I have a table with 8 million records that looks like this: CREATE TABLE
My team is planning to create a simulation game using Javascript, CodeIgniter and MySQL
Eclipse and MyEclipse create new Java files with an extra blank line after the
If I create an application for Android, how do you package extra items in
I've got a table like so: CREATE TABLE IF NOT EXISTS grades(_id, timestamp, extra);
I've trying to optimize a query on MySQL that takes around 15-20 seconds to
I'm trying to run a query on a table that we keep for transactions

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.