设计路由错误:“未知操作 - 无法为UsersController找到操作'create'”

时间:2012-07-10 13:45:55

标签: ruby-on-rails ruby-on-rails-3 devise routes

我的设计设置之前工作正常,但现在,出于某种原因,每当我尝试注册一个新用户时,它都会尝试调用用户#create而不是注册#create。我认为我的routes.rb文件一定是个问题。我最近在我的应用程序中添加了一个新资源“preferences”,因此路由可能会很糟糕:

Indexer2::Application.routes.draw do
  resources :preferences

  get "home/index"

  resources :posts
  resources :users

  devise_for :users, :controllers => {:registrations => 'registrations', :invitations => 'invitations'}, :except => [:show] do
    get "/signup" => "devise/registrations#new", :as => 'user_signup'
    get '/logout' => 'devise/sessions#destroy', :as => 'user_logout'
    get '/login' => "devise/sessions#new", :as => 'user_login'
  end 

  match '/welcome' => 'pages#welcome'

  resources :preferences, :except => [:destory, :edit, :create, :new, :index, :show]  do 
    collection do
      post "make_feed_preference"
      post "change_preference"
    end
  end

  root :to => "home#index"

end

1 个答案:

答案 0 :(得分:2)

您的UsersController应该有create方法。 如果您不想编写自己的注册逻辑,只需从Devise::RegistrationsController < DeviseController继承:

 controller UsersController < Devise::RegistrationsController
      #....
 end

这将包括默认的Devise方法。