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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:55:38+00:00 2026-06-12T15:55:38+00:00

Connecting users and companies uses accepts_nested_attributes_for . When you add a user and save,

  • 0

Connecting users and companies uses accepts_nested_attributes_for. When you add a user and save, the company information is not saved. Does anyone have any idea what could be the problem? Thanks in advance.

user.rb

class User < ActiveRecord::Base
  before_create :create_role
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :remember_me, :role_ids, :company_attributes

  has_one :company, :autosave => true

  accepts_nested_attributes_for :company

  has_and_belongs_to_many :roles


  def role?(role_name)
    return !!self.roles.find_by_name(role_name)
  end

  def with_company
    self.company.build
    self
  end

  private
    def create_role
      self.roles << Role.find_by_name(:user)  
    end
end

sign-up pages new.html.haml

    %div{:style => "margin:10px"}
      %h2= t('devise.shared.links.sign_up')
      %br
      = form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :class => 'form-horizontal'}) do |f|
        = devise_error_messages!
        = f.fields_for :companies do |company_form|
          .control-group
            = company_form.label :name, :class => 'control-label'
            .controls
              = company_form.text_field :name
          .control-group
...
        .control-group
          = f.label :email, :class => 'control-label'
          .controls
            = f.text_field :email
        .control-group
          = f.label :password, :class => 'control-label'
          .controls
            = f.text_field :password
        .control-group
          = f.label :password_confirmation, :class => 'control-label'
          .controls
            = f.text_field :password_confirmation 
        .actions
          = f.submit t("Save"), :class => 'btn btn-primary'
          %br
          %br
          = render "links"

companies controller: https://gist.github.com/3863405

$rails --version
Rails 3.2.2

$ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]
  • 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-12T15:55:40+00:00Added an answer on June 12, 2026 at 3:55 pm

    It looks like you are getting stopped up by mass-assignment protection, despite having attr_accessible :company_attributes in your model…

    Relevant log output:

    WARNING: Can't mass-assign protected attributes: companies
    

    Is that a direct copy/paste from your code, or is it possibly misspelled, or something, in the real code?

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

Sidebar

Related Questions

Does anyone have any sample code in Objective C for connecting to an external
have an application in which many companies post information. the data from each company
Does anyone have any experience with how well web services build with Microsoft's WCF
I have an Excel add-in that allows users to run queries against a SQL
i have multiple users connecting to sql-server-2008 database. i would like to know whether
I have users connecting to my app with Facebook connect. As far as I
We have a SQL Server 2005 database, and currently all our users are connecting
I'm using the Javascript SDK inside a node.js (Express) App. Connecting Users works fine,
I am connecting to an API service which authenticates users using cookies. I make
Is there a way to get the timezone of the connecting user using Pylons,

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.