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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:37:07+00:00 2026-06-01T08:37:07+00:00

I’m trying to set up a simple Roles model for my site. Users can

  • 0

I’m trying to set up a simple Roles model for my site. Users can have any number of roles. Right now I’m setting it up to be a hidden field on the signup form. The problem I’m running into is that in my nested form the role type isn’t being saved. An entry with the uid is being created in the roles table but that’s about it. The relevant code is below. Any help would be appreciated.

 == Schema Information

 Table name: roles

  id         :integer         not null, primary key
  user_id    :integer
  role       :string(255)
  created_at :datetime        not null
  updated_at :datetime        not null

Heres the create method from my users controller…

def create
 @user = User.new(params[:user])  
if @user.save   
  @role = @user.roles.new(user_id:@user.id, role:params[:role])

  flash[:success] = "Thanks for singing up for the Auditions App, any audition invitations will be visible on this page"                 
  #need to add the role guest to user roles
  redirect_to @user
else
  render 'new'
end

end

Heres the form….

<div class="span10 offset1 ajax-form">   
<%= form_for(@user, :html => {:class => 'well'}) do |f| %> 

        <h3>Guest Account Signup</h3>

      <%= render 'shared/error_messages' %>

      <div class="pull-left form-field"><%= f.label :first_name %>
  <%= f.text_field :first_name, :class => 'span4' %></div>
  <div class="pull-left form-field"><%= f.label :last_name %>
  <%= f.text_field :last_name, :class => 'span4' %></div>
  <div class="pull-left form-field"><%= f.label :email %>
  <%= f.text_field :email, :class => 'span4' %></div>                                           
  <div class="pull-left form-field span4"></div>
         <div class='clear'></div><!--close .clear-->

  <div class="pull-left form-field"><%= f.label :password %>
  <%= f.password_field :password, :class => 'span4' %></div>
  <div class="pull-left form-field"><%= f.label :password_confirmation, "Confirm Password" %>
  <%= f.password_field :password_confirmation, :class => 'span4'  %></div>
        <div class="form_row pull-left form-field">
        </div>

            <%= f.hidden_field :role, :value => 'guest' %>

  <%= f.submit "Create my account", :class => "btn btn-large btn-primary pull-left form-field" %>
        <div class='clear'></div><!--close .clear-->
<% 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-01T08:37:09+00:00Added an answer on June 1, 2026 at 8:37 am

    As @Arpit comments – get rid of the hidden :user_id tag. It’s only confounding the attribute setter.

    And I don’t think building multiple roles using roles.new() (is that the same as roles.build()?) is going to cut it. You’ll need to break out the separate roles’ parameters and add them one at a time. Or you can grab them in one go like this:

    selected_roles = Role.find_all_by_id(params[:roles])
    @user.roles = selected_roles
    

    This would assume that you are using role ids in your form, but you aren’t for some reason…

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.