Back to my notorious entity : client relationship.
Entity
has_one :client
Client
belongs_to :entity.
The route:
map.resources :entities do |entity|
# An entity can only have one client role
entity.resource :client, :controller => ‘entity_client’
# An entity can have many locations
entity.resources :locations
# And only one vendor role
entity.resource :vendor
end
Given
the URL = http://localhost:3000/entities/3/client
Naturally enough the default respond_to call to show in
entity_clients_controller.rb expects to find it in views/entity_clients.
Being perverse, I want to display the show.html.erb template in
views/clients. I tried this code in the controller:
def show
@client = Entity.find(params[:entity_id]).client
respond_to do |format|
format.html { redirect_to ‘/clients/show.html.erb’ }
…
But this gives me the error:
Routing Error
No route matches “/clients/show.html.erb” with {:method=>:get}.
I tried modifying routes.rb to this:
map.resources :entities do |entity|
# An entity can only have one client role
entity.resource :client,
:controller => ‘entity_client’,
:method => ‘get’,
:path_prefix => ‘clients’
but that gives me this error:
Unknown action
No action responded to 3
So, what is it that do I not understand here?