Rails RoutingError - 未初始化的常量RegistrationsController:

时间:2015-06-24 18:09:29

标签: ruby-on-rails authentication devise routes

我正在尝试创建一个在json中响应的注册模型,但在尝试注册时,我从rails获取错误“ActionController :: RoutingError - uninitialized constant RegistrationsController:”。任何帮助将不胜感激。

class Api::V1::RegistrationsController < Devise::RegistrationsController


skip_before_filter :verify_authenticity_token
respond_to :json

def register
    build_resource(sign_up_params)
    if resource.save
      render :json => {:result => 'OK'}
    else
      render :json => {:result => 'ERROR'}
  end
end

private

def sign_up_params
    params.require(:user).permit(:email, :password, :password_confirmation)
end

def account_update_params
    params.require(:user).permit(:email, :password, :password_confirmation, :current_password)
end

end

这是我的routes.rb:

(code above...)

devise_for :users, 
    path: '/api/v1/users',
    controllers: { sessions: 'api/v1/sessions', :registrations => "registrations" } do
         get "api/v1/users/sign_up" => "users/registrations#new", :as => :user_signup
         get "api/v1/users/sign_in" => "api/v1/sessions", :as => :user_signin
    end

namespace :api, defaults: { format: :json } do
      namespace :v1 do
          resource :users

(code below...)

这是我的ApplicationController:

class ApplicationController < ActionController::Base
    before_filter :authenticate_user_from_token!
    before_action :authenticate_user!


    private

    def authenticate_user_from_token!
        authenticate_with_http_token do |token, options|
        user_email = options[:email].presence
        user = user_email && User.find_by_email(user_email)

        if user && Devise.secure_compare(user.authentication_token, token)
            sign_in user, store: false
        end
   end
end

耙:

                 new_user_session GET    /api/v1/users/sign_in(.:format)                                                     api/v1/sessions#new
                     user_session POST   /api/v1/users/sign_in(.:format)                                                     api/v1/sessions#create
             destroy_user_session DELETE /api/v1/users/sign_out(.:format)                                                    api/v1/sessions#destroy
                    user_password POST   /api/v1/users/password(.:format)                                                    devise/passwords#create
                new_user_password GET    /api/v1/users/password/new(.:format)                                                devise/passwords#new
               edit_user_password GET    /api/v1/users/password/edit(.:format)                                               devise/passwords#edit
                                  PATCH  /api/v1/users/password(.:format)                                                    devise/passwords#update
                                  PUT    /api/v1/users/password(.:format)                                                    devise/passwords#update
         cancel_user_registration GET    /api/v1/users/cancel(.:format)                                                      registrations#cancel
                user_registration POST   /api/v1/users(.:format)                                                             registrations#create
            new_user_registration GET    /api/v1/users/sign_up(.:format)                                                     registrations#new
           edit_user_registration GET    /api/v1/users/edit(.:format)                                                        registrations#edit
                                  PATCH  /api/v1/users(.:format)                                                             registrations#update
                                  PUT    /api/v1/users(.:format)                                                             registrations#update
                                  DELETE /api/v1/users(.:format)                                                             registrations#destroy
                     api_v1_users POST   /api/v1/users(.:format)                                                             api/v1/users#create {:format=>:json}
                 new_api_v1_users GET    /api/v1/users/new(.:format)                                                         api/v1/users#new {:format=>:json}
                edit_api_v1_users GET    /api/v1/users/edit(.:format)                                                        api/v1/users#edit {:format=>:json}
                                  GET    /api/v1/users(.:format)                                                             api/v1/users#show {:format=>:json}
                                  PATCH  /api/v1/users(.:format)                                                             api/v1/users#update {:format=>:json}
                                  PUT    /api/v1/users(.:format)                                                             api/v1/users#update {:format=>:json}
                                  DELETE /api/v1/users(.:format)                                                             api/v1/users#destroy {:format=>:json}
          api_v1_property_beacons GET    /api/v1/properties/:property_id/beacons(.:format)                                   api/v1/beacons#index {:format=>:json}

0 个答案:

没有答案