不知怎的,我得到了这个路由错误。我没有看到解决方案
我的控制器:
class SubscribersController < ApplicationController
def signup
blabla...
end
etc.....
end
我的routes.rb
Rails.application.routes.draw do
get 'signup' => 'subscribers/#signup'
resources :events
resources :subscribers
root to: 'events#index'
end
所以如果我去http://0.0.0.0:3000/signup 我收到错误:RoutingError uninitialized constant Subscribers
答案 0 :(得分:0)
/
代表命名空间或文件夹,#
用于路由中的操作。您只需删除/
,因为signup
是SubscribersController
下的操作:
get 'signup' => 'subscribers#signup'
答案 1 :(得分:0)
由于您有resources :subscribers
这样的最佳方式来声明非CRUD
操作的路由,例如
resources :subscribers do
member { post :foo } # if is member (operation on single obj) with http post
collection { get :bar } # for collection with http get
end
所以问题的最佳解决方案是
Rails.application.routes.draw do
resources :events
resources :subscribers do
collection { get :signup }
end
root to: 'events#index'
end