rosa-build/admin.bak/users.rb

68 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2014-04-11 21:29:43 +01:00
ActiveAdmin.register User do
menu priority: 2
filter :uname
filter :email
filter :role, as: :select, collection: User::EXTENDED_ROLES
filter :created_at
permit_params :name, :email, :uname, :role, :password, :password_confirmation
2014-04-11 21:29:43 +01:00
controller do
def update(options={}, &block)
user_params = params[:user]
resource.role = user_params.delete(:role)
user_params.delete(:password) if user_params[:password].blank?
user_params.delete(:password_confirmation) if user_params[:password_confirmation].blank?
super
end
end
index do
column :id
column(:uname) do |user|
link_to(user.uname, user_path(user))
end
column :email
column :created_at
column :role
actions
2014-04-11 21:29:43 +01:00
end
form do |f|
f.inputs do
f.input :name
f.input :email
f.input :uname
f.input :role, as: :select, collection: User::EXTENDED_ROLES, include_blank: false
f.input :password
f.input :password_confirmation
end
f.actions
end
action_item(:reset_token, only: :show) do
2014-04-11 21:29:43 +01:00
link_to 'Reset token', reset_token_admin_user_path(resource),
'data-method' => :put,
data: { confirm: 'Are you sure you want to reset token?' }
end
action_item(:login_as, only: :show) do
2014-05-12 21:18:41 +01:00
link_to 'Login as user', login_as_admin_user_path(resource)
end
2014-04-11 21:29:43 +01:00
member_action :reset_token, :method => :put do
resource.reset_authentication_token!
flash[:info] = 'User token reseted successfully'
redirect_to admin_user_path(resource)
end
2014-05-12 21:18:41 +01:00
member_action :login_as do
sign_in(resource, bypass: true)
redirect_to root_path
end
2014-04-11 21:29:43 +01:00
end