开发者

How can I use uncountable nouns in resource routes with Rails 3?

I have a model called Aircraft, inflected as uncountable, and it's driving me nuts. What is the correct way to handle this in 开发者_如何转开发Rails 3 "beta 4"?

resources :aircraft do
  member do
    get :flights
  end
end

# Of course these work for some actions and not others.
match 'aircraft', :to => 'aircraft#index', :as => :aircraft
match 'aircraft/:id', :to => 'aircraft#show', :as => :aircraft_instance


I think it's just:

resources :aircraft, :singular => :aircraft_instance

Then you link_to them like so:

link_to 'Singular aircraft', aircraft_instance_path(@aircraft)
link_to 'All aircraft', aircraft_path(@aircraft)

Edit

It looks like beta4 thinks aircrafts in the plural of aircraft:

rails console
> :aircraft.to_s.pluralize
=> "aircrafts"

If you just put resources :aircraft into your routes, can you link_to both aircraft_path(@aircraft) and aircrafts_path successfully? If so, you may need to write an initializer for ActiveSupport::Inflector to define your own custom inflection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜