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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:17:31+00:00 2026-05-11T12:17:31+00:00

I thought that there should have been a simple solution to this, given that

  • 0

I thought that there should have been a simple solution to this, given that Rails 2.3 has this newfangled nested forms feature. Basically I want to create or update a user and assign them roles at the same time.

It seems like I’m doing everything right but I get the error WARNING: Can’t mass-assign these protected attributes: roles_attrributes.

I even tried changing the view to user[permissions_attrributes][role_id] because I thought that maybe the join table was confusing Rails.

Anyways, any suggestions on how this should actually work?

Model

class User < ActiveRecord::Base    has_many :permissions   has_many :roles, :through => :permissions    accepts_nested_attributes_for :roles   accepts_nested_attributes_for :permissions end 

Excerpt from view (notice I tried and failed to get fields_for to generate what I want here, maybe that’s my problem?)

<% for role in Role.all %>  <%= check_box_tag( 'user[roles_attrributes][id]',role.id) %>  <%= role.rolename %>  <br/> <% end %> 

Params coming across seem to be right:

    {'user'=>{'password_confirmation'=>'[FILTERED]',  'roles_attrributes'=>{'id'=>'2'}, ... 

Solution A combination of me misspelling, not using attr_accessible, needing to access permissions_attributes, and the form being slightly off.

Model:

has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions accepts_nested_attributes_for :permissions attr_accessible :permissions_attributes 

View:

    <%  Role.all(:order => 'rolename ASC').each_with_index do |role,idx| %>     <%= check_box_tag( 'user[permissions_attributes][#{idx}][role_id]',role.id) %>     <%= role.rolename %>     <br/>     <% 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. 2026-05-11T12:17:32+00:00Added an answer on May 11, 2026 at 12:17 pm

    it sounds like this attribute isn’t marked as safe for updating. You should be able to fix it by adding the following to your model class:

    attr_accessible :roles 

    or possibly:

    attr_accessible :roles_attributes 

    If you look, you may already have an attr_accessible call you can add this to. For more information this is documented here:

    http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002226

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

Sidebar

Related Questions

I have always thought that the .equals() method in java should be overridden to
I thought that there was some way in .net 3.0 to give an array
I have always thought that the terms internationalization and localization (and their funny abbreviations
For a long time ago, I have thought that, in java, reversing the domain
I have a method that contains an asynchronous call like this: public void MyMethod()
Summary: I have a struct that is read/written to file. This struct changes frequently,
One of my co-workers claims that even though the execution path is cached, there
I thought that it would be fun to present some classic CS problems and
I thought that to clone a List you would just call: List<int> cloneList =
I thought that I'll be clever and use subquery to get my report in

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.