I have found a lot of posts about this Railscast but all the suggestions haven't helped me. I have been able to render in the view a nested form field, but only one, not the 3 that I have called out in my controller. When I submit, I get the error: Can't mass-assign protected attributes: clue
Chapter.rb
class Chapter < ActiveRecord::Base
belongs_to :trail
has_many :clues, :dependent => :destroy
accepts_nested_attributes_for :clues
attr_accessible :asset, :assetkind, :description, :gate, :name, :trail, :trail_id, :cover
.
.
.
end
Clue.rb
class Clue < ActiveRecord::Base
attr_accessible :chapter_id, :theclue, :typeof, :chapter
.
.
.
belongs_to :chapter
end
In the railcast it says to use the equivalent of :clues, and this renders 3 fields. But in mine, it didn't render the fields. Instead, I use @chapter.clues and it renders only one.
My form when making a new chapter.
<h1>Add a New Chapter</h1>
<h3>Add To Trail : <%= @trail.title %></h3><br>
<%= form_for [@trail, @trail.chapters.build] do |f| %>
<h6>About the Chapter</h6>
<%= f.label :name, 'Chapter Name' %>
.
.
.
<h6>Progressing the Story</h6>
<%= f.fields_for @chapter.clues do |builder| %>
<p>
<%= builder.label :theclue, "Enter Clue" %>
<%= builder.text_area :theclue, :rows => 2 %>
</p>
<% end %>
.
.
.
<% end %>
My chapters_controller.rb new
class ChaptersController < ApplicationController
def new
@trail = Trail.find(params[:trail_id])
@chapter = Chapter.new
@title = "Chapter"
3.times { @chapter.clues.build }
logger.debug "CHAPTER!!!!!!!!!!!!new: am i in a trail? #{@trail.to_yaml}"
logger.debug "CHAPTER!!!!!!!!!!!!new: am i in a clue? #{@chapter.clues.to_yaml}"
end
My log shows me 3 clues, but the attributes are empty (no :id). Is this a sign of something wrong? So even though my log shows 3 clue objects, my view only shows one.
Thoughts? I have already, thanks to suggestions on stackoverflow, added to chapter.rb
attr_accessible :clues_attributes
and had no luck, same behavior and errors with and without that.
Thanks in advance for your time