Forum: Ruby on Rails {ActionController] Default route naming

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-06-05 17:27
I have discovered that if a named resources entry does not have a plural
form then ActionController::Routing uses route_name_index instead.
However, I cannot seem to find any place in the API where this is
mentioned.  Can somebody point out to me where this behaviour is
specified?
3ff9c2544554b13c6c7877e76684751b?d=identicon&s=25 Lee Smith (smitjel)
on 2009-06-05 17:42
(Received via mailing list)
Are you talking about singular resources?

http://guides.rails.info/routing.html#singular-resources

If not, you may want to show how you're declaring your route...
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-06-05 18:50
Lee Smith wrote:
> Are you talking about singular resources?
>
> http://guides.rails.info/routing.html#singular-resources

I am not talking about singular resources.

> If not, you may want to show how you're declaring your route...

  map.resources :forex,
    :type         => 'CABK',
    :controller   => 'currency_exchange_rates',
    :only         => [:index, :show]

$ rake routes
...
forex_index GET    /forex(.:format) {:action=>"index",
                                     :controller=>"currency_exchange_rates"}

      forex GET    /forex/:id(.:format) {:action=>"show",
                                         :controller=>"currency_exchange_rates"}
...
3ff9c2544554b13c6c7877e76684751b?d=identicon&s=25 Lee Smith (smitjel)
on 2009-06-05 21:40
(Received via mailing list)
Looks fine to me...what are you expecting the route to be?
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-06-08 15:49
Lee Smith wrote:
> Looks fine to me...what are you expecting the route to be?

Yes, I confused myself by using both named routes and resources.  That
and I got caught by Rails inflection system as forex has no plural so
that the index action becomes forex_index GET, rather than forexes GET.

I ended up with this sort of thing instead:

  map.forex_by_currency_and_date \
    '/forex/:currency_code/:year/:month/:day',
...

  map.forex_by_currency \
    '/forex/:currency_code',
...

  map.forex_by_date \
    '/forex/:year/:month/:day',
...

  map.resources :forex,
    :type         => 'CABK',
    :controller   => 'currency_exchange_rates',
    :only         => [:index, :show]
  # Note that because forex has no plural form registered in inflections
  # the generated index route is named forex_index
This topic is locked and can not be replied to.