加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 类RegistrationController的超类不匹配 – 覆

发布时间:2020-12-17 01:47:51 所属栏目:百科 来源:网络整理
导读:我试图覆盖我的设计注册控制器,没有运气. 我终于让路由工作了,但现在我得到了类错误的超类不匹配. 继承人我的设置: 注册控制器(app / controllers / users / registrations_controller.rb) class RegistrationsController Devise::RegistrationsController
我试图覆盖我的设计注册控制器,没有运气.

我终于让路由工作了,但现在我得到了类错误的超类不匹配.

继承人我的设置:

注册控制器(app / controllers / users / registrations_controller.rb)

class RegistrationsController < Devise::RegistrationsController

  def sign_up_params
    devise_parameter_sanitizer.sanitize(:sign_up)
    params.require(:user).permit(:email,:password,profile_attributes: [:username])
  end

  def new
    super
  end

  def create

  end

  def update
    super
  end

end

路线

root 'welcome#index'

devise_for :users,:controllers => {:registrations => "users/registrations"}

查看

–edit.html.erbu0026 amp ;> new.html.erb存在于该文件夹中(app / views / users / registrations)

用户模型(以防万一)

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable,:lockable,:timeoutable and :omniauthable
  devise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable

  has_one :profile
  accepts_nested_attributes_for :profile

  def profile
    super || build_profile
  end

end

知道为什么会出现这个错误吗?

谢谢!

解决方法

您的控制器位于users目录下,但没有Users模块(您可能会说,它不在Users命名空间中).将控制器更改为:

module Users
  class RegistrationsController < Devise::RegistrationsController
  ...
  end
end

或者将控制器移到目录中

应用程序/控制器/ registrations_controller.rb

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读