[Redmine 4.0.2] Undefine method "alias_method_chain" Rails 5 upgrade
Added by Tu Nguyen Duy over 5 years ago
Because Rails vesion 5.2 upgrade, method "alias_method_chain" don't work.
Would to expert help me to Replace method "alias_method_chain" in Redmine 4.0.2, rails 5.2.
=============================================================================
require_dependency 'account_controller'
module AccountLockable
module AccountControllerPatch
# unloadable
extend ActiveSupport::Concern
included do
# unloadable
alias_method_chain :invalid_credentials, :account_lock
end
def invalid_credentials_with_account_lock
invalid_credentials_without_account_lock
return if params[:username].blank?
user = User.active.find_by_login(params[:username])
return if user.blank?
login_log = LoginLog.find_or_create_by(user_id: user.id)
login_log.failed!(request.remote_ip)
if login_log.lockable?
user.lock!
login_log.locked!
AccountLockableMailer.account_locked(user, login_log).deliver
end
end
end
end
AccountLockable::AccountControllerPatch.tap do |mod|
AccountController.send :include, mod unless AccountController.include?(mod)
end
=============================================================================
Replies (2)
RE: [Redmine 4.0.2] Undefine method "alias_method_chain" Rails 5 upgrade - Added by Jérôme BATAILLE over 5 years ago
hi !
alias_method_chain :invalid_credentials, :account_lock
becomes :
alias_method :invalid_credentials_without_account_lock, :invalid_credentials
alias_method :invalid_credentials, :invalid_credentials_with_account_lock
RE: [Redmine 4.0.2] Undefine method "alias_method_chain" Rails 5 upgrade - Added by Go MAEDA over 5 years ago
Using Module#prepend
instead of alias_method_chain
is recommended. You can find some good articles by googling with the keywords "alias_method_chain" and "prepend".