我希望这是一件我看不到的简单的事情。我是rails的新手,所以我想这就在我的眼皮底下。
我的应用程序有你所说的stacks,我为它创建了一个资源:
resources :stacks, only: [:new, :create, :show]
我想将show操作的路由从/stacks/:id更改为/stack/:id
我在资源上面添加了这个,但它不起作用:
get '/stacks/:id', to: 'stacks#show', as: 'stack'
谢谢!
编辑:代码
get '/stacks/:id', to: 'stacks#show', as: 'stack'
resources :stacks, only: [:new, :create, :show]发布于 2013-11-15 16:19:31
Ruby on Rails默认情况下会将资源名称复数,用于路由、数据库表名等,但您可以覆盖此行为的特定情况。
转到你的Ruby on Rails应用程序文件夹(为了方便起见,我们将其命名为'.app‘)。在编辑器中打开.app/config/initializers/inflections.rb,您将看到以下内容(Rails 4):
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end添加一个Inflector,这样"stack“就是"stack”的复数,如下所示:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'stack', 'stack'
end这对你来说应该是有用的。
https://stackoverflow.com/questions/19995984
复制相似问题