0

I followed Episode 196 from Railcasts but seem that if i follow his it doesn't work quite yet, maybe cause the code is old or i just don't get rails.

Here I have 3 models

Customer        Book                Book_Manager
id              id                  id
first           description         customer_id
last            book_manager_id     visible
email
password

Here are my relationship

Book
    belongs_to :book_manager
    def customer
        book_manager.customer
    end
Customer
    has_many :book_managers, :dependent => :destroy
    accepts_nested_attributes_for :book_managers
BookManager
    belongs_to :customer
    has_many :books, :dependent => :destroy
    accepts_nested_attributes_for :books

The form is has follow

<%= form_for @bookmanager do |f| %>
  <%= f.fields_for :books do |builder| %>
  <div>
    <%= builder.label :description %><br />
    <%= builder.text_area :description, :rows => 3 %>
  </div>
  <% end %>
  <div class="field">  
    <%= f.label :visible %><br />  
    <%= f.text_field :visible %>  
  </div>  
  <div class="actions">
    <%= f.submit %>
  </div>  
<% end %> 

If i comment out the line

accepts_nested_attributes_for :books

It show the description box, if however i place it there the box does disapear. Did i miss something??

4

1 回答 1

1

I think you have to pass a book object here. Try

<%= f.fields_for :books, Book.new do |builder| %>
于 2012-08-02T15:54:16.717 回答