Custom method routes in a nested has_one resource?

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

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 :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs