- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 contact_us gem 版本 0.5.4
我的 routes.rb 文件中有以下代码
resources :contacts, controller: 'contact_us', only: [:new, :create] do
root :to => 'contact_us#new'
end
在我的理解中,contacts
的上述路由将仅支持 :new
和 :create
操作,以及指定的 Controller controller : 'contact_us'
也有根 /
它将重定向到 #new
操作但是当我点击 http://localhost:3000/contact-us 时在我的浏览器中它说
Unknown action
The action 'index' could not be found for ContactUsController
我已经将 rails 版本从 3.2.19 升级到 4.0.13,将 ruby 升级到 2.0.0p481
旧代码在 rails 3.2.19 和 ruby 1.8.7 上运行良好
resources :contacts,
:controller => 'contact_us',
:only => [:new, :create]
match 'contact_us' => 'contact_us#new'
如果我只在上面的代码中用 get
改变 match
就会抛出这个错误
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.13/lib/action_dispatch/routing/route_set.rb:430:in `add_route': Invalid route name, already in use: 'contact_us' (ArgumentError)
You may have defined two routes with the same name using the
:as
option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created withresources
as explained here:
最佳答案
您可以像在 Rails 3.2 中那样做,您只需要将 match
转换为 get
。不再允许匹配任何动词。
resources :contacts,
:controller => 'contact_us',
:only => [:new, :create]
get 'contact_us' => 'contact_us#new'
编辑
我们通过聊天解决了这个问题。原来是撞到了 gem contanct_us .
关于ruby-on-rails - Rails 4.0.x 如何将 contact_us gem 的根操作路由到指定的操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40655574/
我是一名优秀的程序员,十分优秀!