namespaces - rails nested object form and namespaced controller -
i have nested object this:
class work < activerecord::base belongs_to :issue belongs_to :author has_many :pages, :class_name => 'work' accepts_nested_attributes_for :pages, :allow_destroy => true end class page < activerecord::base belongs_to :work end
and have form create/edit work, fields nested page object. followed this post setting things up, i'm using helper form creates new page when start out.
module adminhelper def make_work(work) returning(work) |w| w.pages.build if w.pages.empty? end end end
then, in form partial have:
- form_for make_work(@work) |f| ... - f.fields_for :page |page_f| = page_f.label :text %br = page_f.text_area :text %p = f.submit "submit"
that displays fields page, when it's submitted looks create action in works controller. create action in admin works controller (namespaced), breaks.
i try namespaced object, if way doesn't know pages:
- form_for make_work([:admin, @work]) |f| ...
how use namespace nested object form has pages method, posts namespaced admin/works controller?
i think should have:
fields_for :pages |page_f| ^
also check in generated html if submit path form correct. in case should like:
/admin/works/3
edit:
example fields_for
:
<% form_for @person |person_f| %> <% person_f.fields_for :emails |email_f| %> <%= email_f.text_field :address %> <% end %> <% end %>
and relationship like:
class person has_many :emails end
make sure didn't iterate on pages this:
<% @work.pages.each |page| %> ... <% fields_for :page |p| %> ...
Comments
Post a Comment