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 8383249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:07:08+00:00 2026-06-09T17:07:08+00:00

Im a RoR rookie and am using rails 3.2.3. I’ve been using devise and

  • 0

Im a RoR rookie and am using rails 3.2.3.

I’ve been using devise and so far it has been great, however, I’ve run into a problem.

I have a User table with devise and a HABTM association with a Role table. I have the join table created and everything is fine. When I create a user and choose it’s role, it creates the data in the join table correctly.

However, I activated devises’ confirmable option and things started to go wrong.
When I create a new user, it no longer inserts the record in the join table as it should.

I mean, all I have literary done was add , :confirmable in front of the other devise options such as :database_authenticatable, :recoverable, :rememberable, :trackable and :validatable.

When I activated :confirmable I wrote this migration (which I saw on stack overflow also):

class AddConfirmableToDeviseV < ActiveRecord::Migration
def change
    change_table(:users) do |t| 
      t.confirmable 
    end
    add_index  :users, :confirmation_token, :unique => true 
  end
end

It sends the email with the link to confirm, nothing wrong with that, but when I click it, the app breaks as that user does not have a role assigned to it, and that is a must.

And as I said, all I did was add :confirmable. If I comment it out like this #,:confirmable in my User model, the role and user data gets inserted in the join table correctly.

What’s going on? Any tips?

Thanks in advance,

Regards

Update

@Kyle C

I’m creating the user with the regular actions:

View:

<div class="field">
    <%= f.label :username %><br />
    <%= f.text_field :username %>
</div>
(...)

<% for role in Role.find(:all) %>
  <div class="field">
  <%= check_box_tag "user[role_ids][]", role.id, @user.roles.include?(role) %>
  <%= role.name %>
  </div>
<%end%>

Then in my controller:

def create

@user = User.new(params[:user])    

respond_to do |format|
  if @user.save
    format.html { redirect_to(@user, :notice => 'User was successfully created.') }
  (...)

Without :confirmable, this is enough to enter the data in the join table.

On top of this, I have this in my app controller:

def after_sign_in_path_for(resource)

if current_user.roles.first.id == 1
  admin_dashboard_path
elsif current_user.roles.first.id == 2
  manage_path
end

end

If i take this out, the user gets logged in when he clicks the confirmation email, however, the middle join table is still doesn’t get the association.

I’ve browsed the documentation (https://github.com/plataformatec/devise/blob/master/lib/devise/models/confirmable.rb)
but I’m still a rookie and I also didn’t find anything that would override my app’s initial behaviour.

Is there a way to force the input of the records in my join table after I create the user?

I’ve tried this:

def create

@user = User.new(params[:user])
@role = Role.find(params[:user][:role_ids])

if @user.save
@user.role << @role
@user.save

AND (wrong thing to do but still without success)

(...)
if @user.save
query = ActiveRecord::Base.connection.raw_connection.prepare("INSERT INTO roles_users (role_id, user_id) VALUES (?,?);")
query.execute(@role.id, @user.id)
query.close

This is really frustrating, anyone else came up with this issue when activating :confirmable with a HABTM?

Thanks for all your help

  • 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-09T17:07:09+00:00Added an answer on June 9, 2026 at 5:07 pm

    t.confirmable is no longer supported please use this migration

       ## Confirmable
      # t.string   :confirmation_token
      # t.datetime :confirmed_at
      # t.datetime :confirmation_sent_at
      # t.string   :unconfirmed_email
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this RoR app that calls to RAILS_ROOT. When running it using rails
I'm a RoR beginner and am using Rails 3.2.3. I have a search form
I've installed RoR in my MacOS X using this guide http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/ Here my versions:
Some of my ror test cases are passing individually when run using the ruby
Am pretty new to ROR. Need help in Rails form validation. Am using rails
Using RoR 2.3.8 Usually we have the following code: Showing <%= @shops.total_entries %> shops
Using RoR 2.3.8. I have two models. It's strange that when I typed text
Am new to RoR paperclip gem and i have been trying out some examples
RoR beginner here using rails 3.2.3 and ruby 1.9.3 Currently I am trying to
I have simple RoR application with devise. Here is the output ot rake routes

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.