0

I have the same problem as here undefined local variable or method `resource_class' in devise . The issue is that the code was already set like the answers. Is it a route problem ? Should I look elsewhere?

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}

undefined method `users_path' for #<#:0x007ff25695fce0>

Is it a syntax error in front ?

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

or is it the block in my routes.rb =>

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

Thanks for your help

Community
  • 1
  • 1
Ehab Elia
  • 13
  • 8

1 Answers1

0

I don't think the problem is devise related : the Devise Readme makes no mention of creating routes for the model used in devise_for

the users_path helper method is enabled from config/routes.rb with the line :

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

or shortly, since you will probably need more routes :

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

Check Rails Routing from the Outside In for more information.

floum
  • 1,149
  • 6
  • 17
  • resources :users, to: 'users#index', as: :users & resources :users, only: [:index] ==> gives me "undefined local variable or method `resource_class' for #<#:0x007fcaf06e76d0>" with the block in _links.html.slim above – Ehab Elia May 29 '16 at 13:00
  • It seems that the problem is in resource_class. Help please, Has been three days I'm trying :( – Ehab Elia May 29 '16 at 13:07
  • Ok, just add only one of the lines (rails way is `resources :users`). Gonna try to look into it further, but i guess you'll have to use something like `link_to :user`. – floum May 29 '16 at 17:39
  • I tried all what passed in my small head. Still got the error "undefined local variable or method `resource_class'" on the block in _links.html.slim above – Ehab Elia May 31 '16 at 11:19
  • from https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview : have you tried `link_to user_omniauth_authorize_path(provider) do ...` ? – floum May 31 '16 at 11:39
  • also see : http://stackoverflow.com/questions/5955224/rails-error-resource-name-devise-help-routing-and-rendering – floum May 31 '16 at 11:39