【问题标题】:AbstractController ActionNotFound for Devise用于设计的 AbstractController ActionNotFound
【发布时间】:2015-02-16 14:41:47
【问题描述】:

我一生都无法弄清楚为什么这不起作用。每当我尝试注册用户时,我都会收到此错误,它说我可能没有将我的路由包装在 devise_scope :user; ...; end;

我的注册控制器:

class Api::V1::RegistrationsController < Devise::RegistrationsController
  skip_before_filter :verify_authenticity_token,
                     if: Proc.new { |c| c.request.format == 'application/json' }

  before_action :configure_permitted_parameters

  respond_to :json

  def create
    build_resource(sign_up_params)

    if resource.save
      login(resource)

      render status: 200,
             json: resource,
             serializer: CurrentUserSerializer,
             root: "user",
             meta: { success: true,
                     info: "Registered" }
    else
      render status: :unprocessable_entity,
             json: { errors: resource.errors.full_messages }
    end
  end

  private

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) do |u|
      u.permit(:name, :email, :password, :password_confirmation)
    end
  end
end

我的路由控制器很重要:

namespace :api do
    namespace :v1 do
      devise_scope :user do
        post   'registrations' => 'registrations#create', as: 'register'
        post   'sessions'      => 'sessions#create',      as: 'login'
        delete 'sessions'      => 'sessions#destroy',     as: 'logout'
      end
    end
end

我不确定为什么会收到此错误。

【问题讨论】:

    标签: ruby-on-rails devise


    【解决方案1】:

    您只需要在使用devise_scope 声明您的自定义路由之前调用devise_for, skip =&gt; :all 添加资源映射,如下所示:

    devise_for :users, skip: :all
    devise_scope :user do
      # custom routes here
    end
    

    供参考,此处讨论:https://github.com/plataformatec/devise/issues/2840#issuecomment-67783871

    【讨论】:

      猜你喜欢
      • 2014-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多