This is probably very simple and I'm overlooking it. I am using devise lockable functions and I would like to create a button that an admin can check to unlock a locked user.
Devise has a model method called unlock_access!. I am trying to call it in my users' controller method with a button in the views.
Views:
= link_to('unlock', user_unlock_path(user), method: :post, class: 'button-xs') unless user == current_user
users_controller.rb:
def unlock
user = User.find(params[:id])
user.unlock_access!
end
route
resources :users do
post 'unlock'
end
I figured it out.
You have to update your route to call the method on a member. Updated the views and controller with working code.
routes
resources :users do
post :unlock, :on => :member
end
updated controller
def unlock
user = User.find(params[:id])
user.unlock_access!
redirect_to users_path
end
updated views
= link_to(t('common.unlock'), unlock_user_path(user), method: :post, class: 'button-xs') unless user == current_user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With