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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:18:55+00:00 2026-05-27T13:18:55+00:00

In my rails application I am having users module which is dependent on roles

  • 0

In my rails application I am having users module which is dependent on roles model.Both are integrated via user_role_assignment model.i.e An user has many roles associated via the user roles assignment.

I am in need to generate a migration to create some default users.
The problem I a facing is if I try to create a user via console,I get an error saying “roles can’t be blank.

u=User.create(:name => "ramyameena", :email => "ramyameena@sandvine.com",:password=>"sandvine",:roles=>{:id=>2,:name=>"Tester"})
=> #<**User id: nil**, name: "ramyameena", created_at: nil, updated_at: nil, email: "ramyameena@sandvine.com", encrypted_password: "$2a$10$qIfRLKZlxviag9E0Gzvp8e3VKkOCaXraP7PnJC6vGMN....", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil>

irb(main):012:0> u.errors.inspect
=> "#<OrderedHash **{:roles=>[\"can't be blank\"]**}>"

My users model:

class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :name, :presence => true, :uniqueness => true
validates :roles, :presence => true
has_many :user_role_assignments
has_many :roles, :through => :user_role_assignments
has_many :tester_release_assignments
has_many :releases, :through => :tester_release_assignments
has_many :releases
has_many :ic_runs
accepts_nested_attributes_for :user_role_assignments
attr_accessible :email, :name, :password, :password_confirmation, :role_ids
  • 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-05-27T13:18:55+00:00Added an answer on May 27, 2026 at 1:18 pm

    You have accepts_nested_attributes_for :user_roles_assignments but on create you’re passing in roles, not user_roles_assignments. I’d check that you aren’t missing accepts_nested_attributes_for :roles or a helper method of some sort…

    Alternatively, you’ll need to do the roles separately. eg

    u = User.new(:name => "ramyameena", :email => "ramyameena@sandvine.com",:password=>"sandvine")
    u.roles.build(:id=>2,:name=>"Tester")
    u.save
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Rails application has a number of tasks which are offloaded into background processes,
I have a rails application where each user has a separate database. (taking Joel
I am building a Rails application which allows a user to create an object
At the moment I have a Ruby on Rails application which maintains my Users,
I'm working on a small Rails application in which I'd like users to be
I'm setting up a Rails 3.1 application in which users can change the theme
I have a rails application that about 3 years old, and I'm having a
My Rails application makes use of Time.zone so that each user can set their
I have a rails application which is still showing the cachebusting numeric string at
I've got a rails application where users have to log in. Therefore in order

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.