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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
redirect_to ''/clients/show.html.erb'' redirect to a html.erb file? you should redirect to an action/controller or use render :template => ''/clients/show.html.erb'' -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> redirect_to ''/clients/show.html.erb'' > > redirect to a html.erb file? > you should redirect to an action/controller > > > or use render :template => ''/clients/show.html.erb''Thanks, that is exactly what I ended up doing. def show @client = Entity.find(params[:entity_id]).client respond_to do |format| format.html { render :template => ''clients/show'' } -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
If you just want to show it, use render :template, don''t use redirect_to. redirect_to will use the routes again, therefore you would need to specify the controller and action (ie you should get url_for to render it for you). Julian. Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) VIDEO #3 out NOW! http://sensei.zenunit.com/ On 10/04/2008, at 3:30 AM, James Byrne wrote:> > 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? > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---