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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:18:03+00:00 2026-06-05T01:18:03+00:00

Begginer Running rails 3.2.2, Ruby 1.8.7 I have 2 models, a Hotel (created by

  • 0

Begginer Running rails 3.2.2, Ruby 1.8.7

I have 2 models, a Hotel (created by scaffolding) and Facility (with empty controller).
I am able to set the 1-to-1 association and siplaying fields but can’t seem to insert it in the databases.
Im getting:

ActiveModel::MassAssignmentSecurity::Error in HotelsController#create
Can't mass-assign protected attributes: @hotel
app/controllers/hotels_controller.rb:48:in 'new'
app/controllers/hotels_controller.rb:48:in 'create'

–> My models are:

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

class Facility < ActiveRecord::Base
  belongs_to :hotel
  attr_accessible :concierge, :hotel_id, :room24h
end

My facility controller, as I said, is empty (it can be, right? since im associating with Hotel?)
My hotel_controller is the default after creating scaffolding, only with 1 added line:

 def new
    @hotel = Hotel.new
    @hotel.build_facility  #-->I added this only, I searched and all i found was this

    respond_to do |format|
      format.html # new.html.erb
      format.json { render :json => @hotel }
    end
  end

 def create
    @hotel = Hotel.new(params[:hotel])

    respond_to do |format|
      if @hotel.save
        format.html { redirect_to @hotel, :notice => 'Hotel was successfully created.' }
        format.json { render :json => @hotel, :status => :created, :location => @hotel }
      else
        format.html { render :action => "new" }
        format.json { render :json => @hotel.errors, :status => :unprocessable_entity }
      end
    end
  end

Finaly, my form html 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 />

    <h2>Hotel Facilities</h2>

    <%= f.fields_for :@hotel 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 %>

The error I am getting when creating is at beggining of question. Should I be adding more code do the hotel_controller? What could it be? Also, what more code would i have to do for the editing/updating?

Thanks in advance and sorry, im new at RoR.

  • 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-05T01:18:05+00:00Added an answer on June 5, 2026 at 1:18 am

    Even though I lot of time has passed, I changed the relation to a HABTM, altered the model and controller and it worked.
    I believe it was due to it being a has_one relation. It needed to be a N-N relationship.

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

Sidebar

Related Questions

I am a begginer in android,here I have activity that use web service: SoapObject
I'm begginer in asp.net mvc and i have some doubts. P.S: I'm using DDD
i am begginer to jquery and have a simple problem.. I want to make
I'm a begginer in cookies and stuff like that. I need to set a
I'm quite a begginer and I have two tables: product and product attributes. Here's
Begginer to Android development. I am developing a application, which have three different tabs.
Begginer's question. I'm trying to write small piece of code in Visual Studio (VB.net)
I am a begginer C++ programmer. In C#, I used the System.Net.Sockets.Socket class, which
I am bigginer to php and i was trying to implement Model-View-Controller in php
i'm just a begginer in perl, and very urgently need to prepare a small

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.