设计错误"undefined local variable or method `resource_class' "



我在设计中遇到了与此处未定义的局部变量或方法'resource_class'相同的问题。问题是代码已经像答案一样设置。是路线问题吗?我应该去别处看看吗?

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :set_locale
  before_action :set_instances
  before_action :configure_permitted_parameters, if: :devise_controller?
  before_action :mixpanel
  def set_locale
   I18n.locale = params[:locale] || I18n.default_locale
  end
  def redirect_to_back
   begin
    redirect_to :back
    rescue ActionController::RedirectBackError => e
    redirect_to root_path
    end
  end
  def set_instances
    @new_event ||= Event.new(title: ".......", capacity: 50, start_date: Time.zone.now, start_time: Time.zone.now, end_time: Time.zone.now)
    @featured_quizz ||= Questionnaire.where('featured IS TRUE')
  end
   helper_method :resource_name, :resource, :devise_mapping
  protected

  def resource_name
   :user
  end
  def resource
    @resource ||= User.new
  end
  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end
  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) << [:name, :firstname, :lastname, :phone]
    devise_parameter_sanitizer.for(:account_update) << [:name, :firstname, :lastname, :image, :phone]
  end
end

=> _links.html.苗条

.row.text-center
.col-md-10.col-md-offset-1
  - if devise_mapping.omniauthable?
    - resource_class.omniauth_providers.each do |provider|
      = link_to omniauth_authorize_path(resource_name, provider), class:"btn btn-fb btn-block callout callout-fb"
        span.fa.fa-facebook-official<>
        span Connectez vous avec #{provider.to_s.titleize}

#<#:0x007ff25695fce0> 的未定义方法 'users_path'

前面是语法错误吗?

  li = link_to "Votre Compte", resource, as: resource_name, url: session_path(resource_name), remote: true, data: { toggle: "modal", target: "#login-modal" }

还是我的路由中的块.rb =>

devise_for :users, :controllers => { 
  :registrations => "registrations",
  :sessions => "sessions",
  :confirmations => "confirmations", 
  :omniauth_callbacks => "callbacks" }
devise_for :admins

感谢您的帮助

我认为问题与设计无关:设计自述文件没有提到为devise_for中使用的模型创建路由

users_path帮助程序方法从config/routes.rb启用

,行:
get '/users', to: 'users#index', as: :users

或很快,因为您可能需要更多路线:

resources :users, only: [:index] # you can skip the :only parameter if you need all restful routes.

有关详细信息,请查看从外向内的导轨布线。

相关内容

最新更新