title: Rails nested forms with pre-defined fields as checkboxes
body: <p>I'm making a hotel app that includes <code>Room</code> and <code>RoomAttribute</code> models. The two models have a <code>many_to_many</code> relationship between each other through a join table. The attributes for each model are as follows:</p>
  
  <ul>
  <li><code>Room</code> – <code>room_number</code>, <code>room_type</code> (e.g. "deluxe" or "suite"), and <code>price</code>. </li>
  <li><code>RoomAttributes</code> – <code>name</code> (e.g. "Wireless Internet", "Cable TV", "Bath Tub").</li>
  </ul>
  
  <p>The user will first create a set of room attributes, so that these can be selected as checkboxes every time a new room is created. For example, some rooms may have wireless internet and some don't. The code for <code>app/views/rooms/new.html.erb</code> is (my apologies for using raw html).</p>
  
  <pre><code>&lt;form action="&lt;%= rooms_path %&gt;" method="post"&gt;
    &lt;input type="hidden" name="authenticity_token" value="&lt;%= form_authenticity_token %&gt;"&gt;
  
    &lt;label for="room_number"&gt;Room Number:&lt;/label&gt;
    &lt;input type="text" name="room[room_number]" id="room_number"&gt; &lt;br&gt;
  
    &lt;label for="room_type"&gt;Type:&lt;/label&gt;
    &lt;input type="text" name="room[room_type]" id="room_type"&gt; &lt;br&gt;
  
    &lt;label for="price"&gt;Price:&lt;/label&gt;
    &lt;input type="text" name="room[price]" id="price"&gt; &lt;br&gt;
  
    &lt;label for="room_attributes"&gt;Attributes:&lt;/label&gt;
    &lt;ul&gt;
      &lt;% @room_attributes.each do |room_attribute| %&gt;
        &lt;li&gt;
          &lt;input type="checkbox" name="room[room_attributes_ids][]" value="&lt;%= room_attribute.id %&gt;"&gt; 
          &lt;%= room_attribute.name %&gt;
        &lt;/li&gt;
      &lt;% end %&gt;
    &lt;/ul&gt;
  
    &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I'm using Rails 4 and I'd like to ask for advice on the following:</p>
  
  <ul>
  <li>Set up the form using form helpers or <a href="https://github.com/justinfrench/formtastic" rel="nofollow">formtastic</a> so that it already outputs all the pre-defined room attributes and users can simply select which attributes to include in the room via checkboxes. </li>
  <li>Write <code>RoomController#create</code> method for this so that it sets the nested <code>RoomAttribute</code> models as room attributes. Do I need <code>accepts_nested_attributes_for :room_attributes</code> in my <code>app/models/room.rb</code>?</li>
  <li><p>How to incorporate strong parameters in this scenario. I've read that I should use </p>
  
  <pre><code>params.require(:room).permit(:room_number, :room_type, :price, room_attributes_attributes: [:id]) 
  </code></pre>
  
  <p>but this is not working for me.</p></li>
  </ul>
  
  <p>Thank you! :)</p>