1
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?

2
  • 2
    resource_class is not available in your _links.slim view. Use User.unlock_strategy_enabled?(:email) instead Commented Nov 29, 2018 at 11:35
  • 1
    This worked. I had tried current_user.unlock_strategy_enabled, thinking it would work, but it did not. Please change the comment to an answer, so I can give you credit for it Commented Nov 29, 2018 at 11:44

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.