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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:26:41+00:00 2026-05-26T06:26:41+00:00

I have a groups#new view. When the current_user is logged in, they are allowed

  • 0

I have a groups#new view. When the current_user is logged in, they are allowed to create a group.

My Groups#new view: the hidden field for the current user works fine, but I need to assign the role = groupleader to this current user.

<div>
  <%= fields_for :membership do   %>
    <%= hidden_field_tag "user_id", current_user.id %>
    <%= hidden_field_tag "role", "groupleader" %>
  <% end %>
</div>
<div class="field">
  <%= f.label :title %><br />
  <%= f.text_field :title %>
</div>
<div class="field">
  <%= f.label :description %><br />
  <%= f.text_area :description %>
</div>
<div class="actions">
  <%= f.submit %>
</div>
<% end %>

Then in my groups#create action:

def create
  @group = Group.new(params[:group])
  @membership = current_user.memberships.build(:group_id => params[:group_id])

This is building a membership but not affecting the role.

My models are as follows:

class Group < ActiveRecord::Base
  has_many :memberships, :dependent => :destroy
  has_many :users, :through => :memberships  
  accepts_nested_attributes_for :users

class User < ActiveRecord::Base #Built with Devise Gem
  has_and_belongs_to_many :roles
  has_many :memberships, :dependent => :destroy
  has_many :groups, :through => :memberships


class Membership < ActiveRecord::Base
  attr_accessible :user_id, :group_id
  belongs_to :user
  belongs_to :group 
end


class Role < ActiveRecord::Base
  has_and_belongs_to_many :users
end

—EDIT
Here is what I am playing with…. since I am sending a role parameter through the form,

@membership = current_user.memberships.build(:group_id => params[:group_id], :role => params[:role])

This is whats going through the log:

 Parameters: {"group"=>{"title"=>"Test group w/leader", "description"=>"test"}, "commit"=>"Create Group", "role"=>"groupleader", "authenticity_token"=>"+GCK8bJddObwKdCoiqI5QzlGRyuci8b5JxmgXbOjgsc=", "utf8"=>"✓", "user_id"=>"8"}
 User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 8 LIMIT 1
WARNING: Can't mass-assign protected attributes: role

Obviously, I have a mass-assign issue.

  • 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-26T06:26:42+00:00Added an answer on May 26, 2026 at 6:26 am

    Your membership model doesn’t have attr_accessible for groupleader. Can’t this me the reason why is it not working.

    Also I suggest naming it as group_leader_id

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

Sidebar

Related Questions

i have class named Group i tried to test configuration: var cfg = new
I have a ModelForm where i give users a chance to create a new
I am new to ror. I have 2 tables for group (called 'ab') and
I have groups of people. I need to move groups with at least one
In my application I have groups which are essentially just tags that can be
If I have groups of checkboxes like so: <input type=checkbox namecheckboxes1 value=#value1> <input type=checkbox
I have a Groups table and a Participants table. Now I need to insert
I have 2 groups of radio buttons with links corresponding to each of the
I have 3 tables users(id,name),groups(id,name) and users_groups(user_id,group_id). users and groups have many to many
What's a good algorithm to solve this problem? I have three groups of people

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.