Simple Rails Path Question
I have a controller route defined as follows:
resources :watched, :controller => "watched", :only => :index
When 开发者_如何学JAVAI run rake routes
, I get the following:
watched_index GET /watched(.:format) {:action=>"index", :controller=>"watched"}
For some reason, neither watched_path
or watcheds_path
seems to be defined in my views. Any ideas?
According to your output from rake routes, the path you should be using is either of the following:
watched_index_path
watched_index_url
You're using resources
so Rails is pluralizing your resource:
> 'watched'.pluralize
=> "watcheds"
You can define a manual pluralization in your config/initializers/inflections.rb
, but you should stick to nouns for your resources, since they're the only thing that makes much sense. Who is being watched? What is this resource actually showing?
Example of defining an irregular inflection:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'thesinglewatched', 'themanywatched'
# or...
inflect.uncountable 'watched'
end
try watcheds_path
and let me know if this works
精彩评论