Changing the URL if in nested resources

I have a nested restful resource working

map.resources :works do |work|
work.resources :work_sections
end

producing a url like:
/works/2/work_sections/1

I’d like to do two things with the URL, but am not sure where to start.

  1. I’d like to restrict the work_section from displaying if the work_id
    isn’t legit.
    Right now /works/2/work_sections/1 will pull up work_section_id 1 even
    if it
    is associated with work_id 1 (contrary to the url)

  2. Make it so that the work_section number in the URL is the :position
    (as
    opposed to :id) for the work_section which is an acts_as_list child of
    work.
    I want to avoid ending up with a url like:
    /works/223/work_sections/12838

I’m pretty sure accomplishing #2 will include my want for #1.

Is there an example or particular concept I need to look to research how
to
do this type of routing?

Rich Vázquez, CISSP, CISA

Check that in your controller code, make sure you use
work_object.work_sections.find()

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