i have a nested object like 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 i have a form to create/edit a work, with fields for the nested page object. i followed this post (nested object forms) for setting things up, so i'm using a helper so that my form creates a new page when you start out.
module AdminHelper
def make_work(work)
returning(work) do |w|
w.pages.build if w.pages.empty?
end
end
end
then, in my form partial i have:
- form_for make_work(@work) do |f|
...
- f.fields_for :page do |page_f|
= page_f.label :text
%br
= page_f.text_area :text
%p
= f.submit "Submit"
that displays the fields for the page, but when it's submitted it looks for the create action in the works controller. the create action is in the admin works controller (namespaced), so that breaks.
i try it with the namespaced object, but if i do it this way it doesn't know about pages:
- form_for make_work([:admin, @work]) do |f|
...
how do i use the namespace with the nested object form so that it has the pages method, but posts to the namespaced admin/works controller?