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??

0

1 Answer 1

1

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

<%= f.fields_for :books, Book.new do |builder| %>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it works, now i just need to set my create and update actions thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.