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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:31:24+00:00 2026-06-01T20:31:24+00:00

I’m a newbie and have searched many posts and railscast tutorials and still cant

  • 0

I’m a newbie and have searched many posts and railscast tutorials and still cant get around this associations thing.

I have 2 models, a Hotel (created by scaffolding) and Facility.

The point is to associate a facility to a hotel, but since my facility table has all the columns it needs with boolean type), a row in that table would do for one hotel.

The thing is, I can’t get it to show, and save/edit/update de facilities. I’ve created a hotel_id colum when creating the model Facility.
My code is:

Models:

class Facility < ActiveRecord::Base

  belongs_to :hotel

  attr_accessible :concierge, :hotel_id, :room24h

end


class Hotel < ActiveRecord::Base

  has_one :facility, :dependent => :destroy


  accepts_nested_attributes_for :facility, :allow_destroy => true

  attr_accessible :name, :rating, :recommended, :facility_attributes

end

My form in the view is:


<%= form_for(@hotel) do |f| %>

  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>

  <div class="field">
    <%= f.label :rating %><br />
    <%= f.number_field :rating %>
  </div>

  <div class="field">
    <%= f.label :recommended %><br />
    <%= f.check_box :recommended %>
  </div>

  <br />
    Hotel Facilities

    <%= f.fields_for :facility do |facility_fields| %>
 <div class="field">
    <%= facility_fields.label :room24h, "24h Room Service:" %>
    <%= facility_fields.check_box :room24h %>
  </div>

 <div class="field">
    <%= facility_fields.label "Concierge:" %>
    <%= facility_fields.check_box :concierge %>
  </div>

<%end%>

  <div class="actions">
    <%= f.submit %>
  </div>
<%end%>

As for Controllers, the hotels_controller is the same as if you had just done scaffolding and my facilities_controller is empty.

It is now showing the facilities in the form, but when i click “Create” and it submits, I get:

"Can't mass-assign protected attributes: @hotel"

and

app/controllers/hotels_controller.rb:46:in `new'
app/controllers/hotels_controller.rb:46:in `create'

as for parameters input:

{"hotel"=>{"rating"=>"1",
 "name"=>"aaa",
 "recommended"=>"0",
 "@hotel"=>{"room24h"=>"1",
 "concierge"=>"1"}},
 "commit"=>"Create Hotel",
 "utf8"=>"✓",
 "authenticity_token"=>"YU7KEJ8qz0iQcXPGkLP6BSJn7JL6df1HvuS5JnjK2eU="}

Any ideas? What is missing in the controllers? Thanks in advance again

  • 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-01T20:31:26+00:00Added an answer on June 1, 2026 at 8:31 pm

    In New/Edit action create @hotel.facility || @hotel.build_facility

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.