Nicolas
unread,Oct 4, 2010, 12:39:55 AM10/4/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Talk
Hi all,
I'm having some issues to create a nested form with Rails3, the fields
for creating my "children" object are not displayed in the form of its
parent form.
The code below is working under rails2 and not rails3, after reading
the rails3 release note, they didn't make any changes about nested
attributes. So it should work, or maybe I've missed something...
#model/book.rb
class Book < ActiveRecord::Base
has_one :author
accepts_nested_attributes_for :author
end
#model/author.rb
class Author < ActiveRecord::Base
belongs_to :book
end
#views/books/_form.html.erb
<%= form_for(@book) do |f| %>
...
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<!-- For some reasons this block doesn't show up under rails3
but in rails 2 it's working -->
<% f.fields_for :author do |author_form|%>
<div class="field">
<%= author_form.label :name%>
<%= author_form.text_field :name %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
#controllers/books_controller.rb
def new
@book = Book.new
@book.build_author
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @book }
end
end
I would appreciate any help, thanks. And I apologize if I made any
english errors.
Nico.