# Custom method routes in a nested has\_one resource?

**URL:** <https://www.ruby-forum.com/t/custom-method-routes-in-a-nested-has-one-resource/145978>\
**Category:** Rails\
**Created:** [August 15, 2008, 6:39pm UTC](https://www.ruby-forum.com/t/custom-method-routes-in-a-nested-has-one-resource/145978 "2008-08-15T18:39:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [August 15, 2008, 6:39pm UTC](https://www.ruby-forum.com/t/custom-method-routes-in-a-nested-has-one-resource/145978/1 "2008-08-15T18:39:32Z")

</div>

I’m struggling with the syntax for some routes - can anyone set me  
straight?

a lesson has\_one plan.  
lesson has a bunch of custom methods (this is all fine)  
plan needs some custom methods as well - i have these set up in a  
non-nested way, eg  
/plans/1/plan\_pdf  
rather than, as it should be,

/lessons/23/plan/plan\_pdf

My regular actions all work in a nice, nested way:

/lessons/23/plan [GET]  
goes to the show action. It’s just the custom actions i can’t work out

- where do i put them in routes.rb? this is what i have already for  
lessons and plans:

map.resources :lessons, :has\_one =\> [:plan], :member =\> { :preview =\>  
:get, :detail =\> :get, :download =\> :get, :online\_xml =\> :get,  
:offline\_xml =\> :get, :remove\_asset =\> :get, :delete\_missing\_elements =\>  
:post, :update\_asset\_positions =\> :get, :scorm\_download =\> :get,  
:add\_non\_interactive\_activity =\> :post }

map.resources :plans, :has\_many =\> [:schedule\_columns,  
:schedule\_entries], :member =\> {:add\_learning\_objective =\> :post,  
:plan\_pdf =\> :get}

It never makes sense to call a plan outside of the context of a lesson  
so it’s fine to make plan a totally nested resource: just as a has\_one  
rather than has\_many.

thanks  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [August 15, 2008, 6:52pm UTC](https://www.ruby-forum.com/t/custom-method-routes-in-a-nested-has-one-resource/145978/2 "2008-08-15T18:52:21Z")

</div>

Actually i think i figured it out - this seems to work ok:

map.resources :lessons, :member =\> { :preview =\> :get, :detail =\> :get,  
:download =\> :get, :online\_xml =\>  
:get,  
:offline\_xml =\> :get, :remove\_asset  
=\> :get,  
:delete\_missing\_elements =\> :post,  
:update\_asset\_positions =\> :get,  
:scorm\_download =\> :get,  
:add\_non\_interactive\_activity =\>  
:post  
} do |lessons|  
lessons.resource :plan, :has\_many =\> [:schedule\_columns,  
:schedule\_entries],  
:member =\> {:add\_learning\_objective =\> :post,  
:plan\_pdf =\> :get}  
end

seems kind of obvious now 🙂
