EastsideDev
EastsideDev

Reputation: 6639

Undefined local variable or method with Rails & Devise

Rails 3.2
Devise
Devise security extensions

In my app/views/users/shared/_links.slim, I have:

- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
  li.home-nav= link_to t('users.shared.didnt_received_unlock'), new_unlock_path(resource_name)

In my User model, I have:

devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable,  :invitable, :confirmable,
     :password_expirable, :password_archivable, :session_limitable, :expirable, :secure_validatable,
     :lockable, :timeoutable

When a user tries to log in, I get the following error:

NameError (undefined local variable or method resource_class' for #<#<Class:0x000000098a1598>:0x000000092d4b60>): app/views/users/shared/_links.slim:5:in_app_views_users_shared__links_slim___1531266065579142927_70700660' app/views/layouts/application.html.slim:96:in _app_views_layouts_application_html_slim___452855375923455357_79638440' app/middleware/catch_json_parse_errors.rb:8:incall'

Any ideas?

Upvotes: 1

Views: 404

Answers (1)

Dipil
Dipil

Reputation: 2708

resource_class is only available in the Devise controller, and not in your _links.slim view. Use User.unlock_strategy_enabled?(:email) instead

Upvotes: 2

Related Questions