简体   繁体   中英

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:in call'

Any ideas?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM