Add Shortcut to Nested Route

Posted by wakeless on Stack Overflow See other posts from Stack Overflow or by wakeless
Published on 2010-05-11T10:50:11Z Indexed on 2010/05/11 10:54 UTC
Read the original article Hit count: 209

I'm using nested routes and I want to provide some sort of a shortcut method. (I'm using RoR 3.0)

The routes look like this.

resources :countries do
  resources :regions do
    resources :wineries
  end
end

To access a winery route I want to be able to define a function that removes the need to specify a country and region each time. Like:

def winery_path(winery)
  country_region_winery_path (winery.country, winery.region, winery)
end

Where should I do this? How can I get that to be available whereever url_for is available?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails3