# Restful routing help

**URL:** <https://www.ruby-forum.com/t/restful-routing-help/145393>\
**Category:** Rails\
**Created:** [August 8, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/restful-routing-help/145393 "2008-08-08T18:45:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [August 8, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/restful-routing-help/145393/1 "2008-08-08T18:45:18Z")

</div>

Ok so I am making a directory, the flow of the directory should be  
category to state to county to city to zip. I cant get it to work so  
that when you click on a certain category it links to you all the  
states it has. so far this is what i have.

routes.rb

map.resources :categories, :has\_many =\> :states  
map.resources :states, :has\_many =\> :counties  
…

So they start off in the show action of the categories controller  
which is

categories\_controller.rb

def show  
@categories = Category.find(:all)  
respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @categories }  
end  
end

here is my show view for categories

show.html.erb

# Listing categories
\<% for category in @categories %\> \<% end %\>

| \<%= link\_to category.title, state\_path(@state) %\> |

here is my states controller

states\_controller.rb

def index  
@states = @category.states  
respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @states }  
end  
end

and here is my index view for states

index.html.erb

# Listing States
\<% for states in @categories.states %\> \<% end %\>

| \<%= link\_to state.title, county\_path(@county)%\> |

now I can get to the categories view and see all the categories but  
when I click on a specific category to go to show all the states it  
has it throws a error. Any help would be greatly appreciated, thnks  
in advance.

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [August 9, 2008, 9:18am UTC](https://www.ruby-forum.com/t/restful-routing-help/145393/2 "2008-08-09T09:18:28Z")

</div>

Does anyone know? or can point me in the right direction?
