RoutingError未初始化的常量订阅者

时间:2017-05-10 08:47:35

标签: ruby-on-rails ruby

不知怎的,我得到了这个路由错误。我没有看到解决方案

我的控制器:

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

2 个答案:

答案 0 :(得分:0)

/代表命名空间或文件夹,#用于路由中的操作。您只需删除/,因为signupSubscribersController下的操作:

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

有关详细信息,请参阅http://guides.rubyonrails.org/routing.html