I have the following associations:
Entity
has_one :client_role
ClientRole
belongs_to :entity
There should be two ways to add a client role, one where the entity
exists and one where the entity does not.
In the case where the entity does not exist I have wired the client
controller to initialize an entity and an entity.client, populate both
from client/new, and add both via client/create. This works.
Here is my problem.
The client/edit method can logically be reached either from
clients/index (client role exists) or from entities/index (client role
may or may not exist). However, the :id passed via params in each case
refers to a different model, client and entity respectively. Ideally,
when calling from entities/index where no client role exists I should
call new_client_path. However, new in this sense implies an existing
entity, something that I cannot pass via new_client_path and which would
not be understood by clients_controller.new as written in any case.
Basically, what I must do is detect what model the :id passed belongs
too in edit and set up the necessary objects dependent upon that
determination. Or, I have to call a method so that this determination
is already satisfied. I cannot simply find against both models inside
the controller and see which one fails since it is possible that the
edit call is for an existing client role. Further, when a new client
role is required the entity id: passed might refer to an entirely
different client role which then would be returned in error.
Is this a case where I need a separate controller and special entry in
the routes file to handle this need?
map.resources :clients
map.resources :entities do |entity|
entity.resources :client, :controller => ?, :method =>
edit/new?
end
Thanks in advance for any assistance offered.