# Map.resources + has\_many + STI + :only

**URL:** <https://www.ruby-forum.com/t/map-resources-has-many-sti-only/177523>\
**Category:** Rails\
**Created:** [October 19, 2009, 5:57pm UTC](https://www.ruby-forum.com/t/map-resources-has-many-sti-only/177523 "2009-10-19T17:57:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartOn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@MartOn](https://www.ruby-forum.com/u/MartOn)\
**Post date:** [October 19, 2009, 5:57pm UTC](https://www.ruby-forum.com/t/map-resources-has-many-sti-only/177523/1 "2009-10-19T17:57:35Z")

</div>

Hello

I have product model that has a given workflow (given by  
state\_machine). Then I have 2-3 versions of product that have a  
slightly different workflow. Since state\_machine has a elegant way of  
handling class inheritance (compared to aasm), I have 2-3 models that  
inherit from Product. (ProductOne, ProductTwo, etc). The Product model  
has\_many transisions. this is a hm relationship that basically handles  
all transisions/events RESTfully. I also get transision logging by  
having this transision model.

My question is how this is implemented as DRY as possible in  
routes.rb. this is how my routes.rb looks like today:

map.resources :products do |product|  
product.resources :transisions, :only =\> [:index, :new, :create]  
end  
map.resources :product\_one, :as =\> ‘products’, :controller =\>  
‘products’ do |product|  
product.resources :transisions, :only =\> [:index, :new, :create]  
end  
map.resources :product\_two, :as =\> ‘products’, :controller =\>  
‘products’ do |product|  
product.resources :transisions, :only =\> [:index, :new, :create]  
end  
map.resources :product\_three, :as =\> ‘products’, :controller =\>  
‘products’ do |product|  
product.resources :transisions, :only =\> [:index, :new, :create]  
end

Is there a more elegant way to handle this. goal is to have only  
“products” routes. I do not want separate routes for each variant of  
product.

I tried this but it did not work :-):  
map.resources :products, :has\_many =\> [ :transisions =\> { :only =\>  
[:index, :new, :create] } ]

/MartOn
