# How to get the right template

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-right-template/134312>\
**Category:** Rails\
**Created:** [April 9, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/how-to-get-the-right-template/134312 "2008-04-09T19:30:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 9, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/how-to-get-the-right-template/134312/1 "2008-04-09T19:30:08Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 9, 2008, 8:09pm UTC](https://www.ruby-forum.com/t/how-to-get-the-right-template/134312/2 "2008-04-09T20:09:11Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 9, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/how-to-get-the-right-template/134312/3 "2008-04-09T21:11:46Z")

</div>

Thorsten M. 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’ }

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 10, 2008, 8:33am UTC](https://www.ruby-forum.com/t/how-to-get-the-right-template/134312/4 "2008-04-10T08:33:07Z")

</div>

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/](http://sensei.zenunit.com/)
