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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:47:40+00:00 2026-06-17T15:47:40+00:00

Trying to use nested attributes to create an Organization and a User in one

  • 0

Trying to use nested attributes to create an Organization and a User in one form. I’m getting the following error: Can’t mass-assign protected attributes: user (ActiveModel::MassAssignmentSecurity::Error)

Pulling my hair out on this one

organization.rb

class Organization < ActiveRecord::Base  
  attr_accessible :name, :users_attributes
  has_many :users, dependent: :destroy      
  accepts_nested_attributes_for :users  
end

user.rb (using devise)

class User < ActiveRecord::Base
  attr_accessible :email     
  belongs_to :organization
end

new.html.haml

= form_for @organization do |f|

  = f.label :name, "Company Name"
  = f.text_field :name, placeholder: "Company Name"

  = f.fields_for :user do |ff| -# tried :users here and the form doesn't render
    = ff.label :email, "Email Address"
    = ff.email_field :email, placeholder: "Email Address"

= f.submit "Create Account"
  • 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-17T15:47:42+00:00Added an answer on June 17, 2026 at 3:47 pm

    This has been answered a lot on Stackoverflow.

    f.fields_for :users
    

    And in the controller, you need to build a user:

    @organization.users.build
    

    You get Can't mass-assign protected attributes: user because the user attribute is not accessible, because it doesn’t exist.

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

Sidebar

Related Questions

I am trying to use a nested form but keep getting this error when
I am trying to use nested attributes on my user model for settings so
I'm trying to use rails nested form_for helper, but I am getting the following
I'm trying to use nested aggregation for one of my queries: SELECT t.type, t.avgrent
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying to use the entity framework to take data (nested relationships) from one
I am trying to set up a nested model form similar to the one
What I'm trying to do is the following: At anyone time a user can
I am trying to accomplish a module where i need to use nested templates
Hi I am trying to understand the best practise to use nested views. I

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.