Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise Unlock Button in Views

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
like image 977
AGirlThatCodes Avatar asked Dec 18 '14 22:12

AGirlThatCodes


1 Answers

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
like image 63
AGirlThatCodes Avatar answered Oct 22 '22 17:10

AGirlThatCodes