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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:20:27+00:00 2026-06-15T20:20:27+00:00

I have set up 2 models as following : class Sector < ActiveRecord::Base attr_accessible

  • 0

I have set up 2 models as following :

class Sector < ActiveRecord::Base
  attr_accessible :summary, :title, :sector_ids

  belongs_to :platform
end

and

class Platform < ActiveRecord::Base
attr_accessible :name, :url
    has_many :sectors
end

and a form which tries to use example from here as follows :

<%= simple_form_for @platform, :html => { :class => 'form-vertical'} do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <div class="row-fluid">
        <div class="span12">
            <div class="span6">
              <%=  field_set_tag "General" do %>
    <%= f.input :name %>
    <%= f.input :url %>
<%= f.collection_check_boxes :sector_ids, Sector.all, :title, :title %>

    <% end %>
</div>
</div>
</div>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>

nevertheless, after I try to submit the form I get the following error :

Can’t mass-assign protected attributes: sector_ids

What am I missing here? I successfully migrated the database after adding appropriate associations, but it seems like Rails doesnt really know what to do now wit the sector ids that are selected.

Solution :

class Sector < ActiveRecord::Base
  attr_accessible :summary, :title

  belongs_to :platforms
end

and

class Platform < ActiveRecord::Base
attr_accessible :name, :url, :platform_attributes, :sector_ids
    has_many :sectors
end

and in the view :

<%= f.association :sectors, :as => :check_boxes %>

Ofcourse, do not forget to run “rake db"migrate“, in case you havent done it yet. I was also required to restart the server in order for the changes to apply.

I hope this helps someone.

  • 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-15T20:20:28+00:00Added an answer on June 15, 2026 at 8:20 pm

    First I think you should remove :sectors_ids from the attr_accessible of Sector and try.

    If the above doesn’t works (which probably may not work), see the documentation of simple_form, specially read https://github.com/plataformatec/simple_form#associations and https://github.com/plataformatec/simple_form#collection-check-boxes; the last one makes what you are trying to do, but, in the associations they use has_and_belongs_to_many associations.

    Finally, check this out https://github.com/plataformatec/simple_form/issues/341

    Update
    The solution is to make a has_and_belongs_to_many relationship, there is no way out, because, you want to associate some sectors to one platform, but, you want to associate the same sectors to other platforms, otherwise you won’t need checkbox, only nested forms to keep adding new records. You have to make this change in your database design and structure.

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

Sidebar

Related Questions

I have the following models set up: class Contact < ActiveRecord::Base belongs_to :band belongs_to
I have the following models: class Price < ActiveRecord::Base belongs_to :product end class Metric
I have the following models: class User < ActiveRecord::Base has_many :subscriptions end class Subscription
I have the following models: class Aircon < ActiveRecord::Base belongs_to :shop belongs_to :brand belongs_to
I have the following models: class Aircon < ActiveRecord::Base belongs_to :shop belongs_to :brand belongs_to
I have the following models: class Product < ActiveRecord::Base belongs_to :brand belongs_to :model accepts_nested_attributes_for
I have the following setup: Models: class Product < ActiveRecord::Base has_one :product_category attr_accessible :name,
I have the following three models: class Facebook < ActiveRecord::::Base end class Facebook::Like <
I have the following models set up: class Player < ActiveRecord::Base has_many :game_players has_many
I have the following models: class Match < ActiveRecord::Base has_and_belongs_to_many :teams end And class

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.