2016-05-27 91 views
0

我有和這裏undefined local variable or method `resource_class' in devise相同的問題。問題是代碼已經被設置爲答案。這是路線問題嗎?我應該看看別處嗎?設計錯誤「未定義的局部變量或方法`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.slim

.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} 

未定義的方法`users_path」爲#<#:0x007ff25695fce0>

它是在前面的語法錯誤?

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

或者是它在我的routes.rb塊=>

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

感謝您的幫助

+2

在控制檯中鍵入「bundle exec rake routes」併發布上面的輸出。 – bkunzi01

+0

我試過了,它很危險。超過36000個字符。不能在一個新的問題 –

回答

0

我不認爲這個問題是制定相關:在Devise Readme隻字不提爲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. 

檢查Rails Routing from the Outside In以獲取更多信息。

+0

資源:用戶,爲:'用戶#索引',作爲::用戶和資源:用戶,只:[:索引] ==>給我「未定義的局部變量或方法」 resource_class'for#<#:0x007fcaf06e76d0>「與_links.html.slim上面的塊在 –

+0

之上似乎問題出在resource_class。請幫助,已經三天了,我正在嘗試:( –

+0

好吧,只需添加其中一行(rails的方式是'resources:users')。要試着進一步研究它,但我想你必須使用類似'link_to:user'的東西 – floum

相關問題