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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:41:37+00:00 2026-06-10T04:41:37+00:00

I have a model that has amenities with a 1:1 relationship: class Listing <

  • 0

I have a model that has amenities with a 1:1 relationship:

  class Listing < ActiveRecord::Base

      attr_accessible :address1, :address2, :bath, :bedroom, :city, :description, :neighborhood, :sleeps, :sqft, :state_id, :title, :zip, :images_attributes, :amenity_attributes

      has_many :images, :dependent => :destroy
      accepts_nested_attributes_for :images, :allow_destroy => true

      has_one :amenity
      accepts_nested_attributes_for :amenity, :allow_destroy => true
   end

And Amenities table:

class Amenity < ActiveRecord::Base
  attr_accessible :air_conditioning, :balcony

  belongs_to :listing

end

Lastly, my view:

   <%= simple_nested_form_for (@listing), :html => {:multipart => true} do |f| %>
          <%= f.error_notification %>
          <div class="form-inputs">
            <%= f.input :title %>
            <%= f.input :sleeps %>
            <%= f.input :bath %>
            <%= f.input :bedroom %>
            <%= f.input :sqft %>
            <%= f.input :neighborhood %>
            <%= f.input :address1 %>
            <%= f.input :address2 %>
            <%= f.input :city %>
            <%= f.input :state_id %>
            <%= f.input :zip %>
            <%= f.input :description %>
          </div>

            <!-- amenities -->
            <%= f.fields_for :amenities do |a| %>
                <div class="amenities">
                    <label><%= a.check_box :smoking %> Smoking Allowed</label>
                </div>
            <% end %>
                <!-- end amenities -->
    <!-- Submit button -->
<% end %>

When I hit submit I get the error:

Can't mass-assign protected attributes: amenities

Any idea what’s up here? It won’t submit even though I allow :amenities_attributes and accepts_nested tags.

  • 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-10T04:41:39+00:00Added an answer on June 10, 2026 at 4:41 am

    Fixed:

    class Listing < ActiveRecord::Base
      has_one :amenity
      accepts_nested_attributes_for :amenity
      after_initialize do
        self.amenity ||= self.build_amenity()
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that has a unique generic foreign key relationship: class Contact(models.Model):
I have a model that has an array of Strings called tags, public class
If I have model that has a 1 to 1 relationship with another, do
I have a model that has counter_cache enabled for an association: class Post belongs_to
I have a Person model that has a foreign key relationship to Book ,
I have an ActiveRecord model that has a long string field. Actually, this string
I have an Article model that has a foreign key relationship with Author that
I have a model that has a ForeignKey to the built-in user model in
I have a model that has an arbitrary number of children entities. For simplicity
I have category model that has a tree structure. In my database I have

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.