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

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer All you need to do is load a small flash… May 11, 2026 at 6:03 pm
  • Editorial Team
    Editorial Team added an answer Have you measured this and determined that this traversal is… May 11, 2026 at 6:03 pm
  • Editorial Team
    Editorial Team added an answer You can attach Sql Profiler to the server to see… May 11, 2026 at 6:03 pm

Related Questions

This question is a little involved. I wrote an algorithm for breaking up a
I'm really confused. I want to do something that a) seems like it should
I have a method that contains an asynchronous call like this: public void MyMethod()
For an open source project I have I am writing an abstraction layer on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.