Let''s say I have a model class like this
class Parent < ActiveRecord::Base
has_many :things
has_one :special_thing, :classname => ''Thing'', ...
end
and I want the associations to be handled by UserThingsController and
UserSpecialThingsController respectively. Theny, apparently, I have to
set up routes with explicit :controllers
map.resources :parents do parent|
parent.resources :things, :controller => :user_things
parent.resource :special_thing, :controller => :user_special_things
end
Or is there a way to get this automatically?
As I want to edit the nested resources in-place on the same page as
their parent object, I have a view, that contains a forms like these
<% form_for(@special_thing, :url => image_path) do |f| %>
<%= f.text_field :name %>
<% form_for(@things[0], :url => image_path) do |f| %>
<%= f.text_field :name %>
The first thing to notice is that I have to give the :url argument, for
otherwise both forms would go to ThingsController instead of
the "nested" controllers.
Second, the element ids and names are unusable. What I get is
<form action="/parent/1/special_thing"
id="new_thing" method="post">
<input
id="thing_name"
name="thing[name]"
type="text" />
Whereas what I need is, for the has_one case,
<form action="/parent/1/special_thing"
id="new_thing" method="post">
<input
id="parent_special_thing_name"
name="parent_special_thing[name]"
type="text" />
and for the has_many case with the appropriate object ids used in
names/ids.
I just can''t get this stuff to do (easily) what I think it ought to do.
That may well be an indication that I''m misunderstanding something
considerably. What''s the right way?
Michael
--
Michael Schuerig
mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org
http://www.schuerig.de/michael/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---