Skip to content

Instantly share code, notes, and snippets.

@rmaceissoft
Created March 19, 2012 22:01
Show Gist options
  • Save rmaceissoft/2127513 to your computer and use it in GitHub Desktop.
Save rmaceissoft/2127513 to your computer and use it in GitHub Desktop.
manual confirmation from admin (rails_admin) using custom action
# located at #{Rails.root}/config/initializers/rails_admin.rb
# RailsAdmin config file. Generated on March 01, 2012 17:53
# See github.com/sferik/rails_admin for more informations
RailsAdmin.config do |config|
config.current_user_method { current_user } # auto-generated
config.main_app_name = ['Timetracker', 'Admin']
config.authorize_with do
redirect_to new_user_session_path unless current_user.try(:admin?)
end
# Use a specific role for ActiveModel's :attr_acessible :attr_protected
# Default is :default
# current_user is accessible in the block if you want to make it user specific.
config.attr_accessible_role { :admin }
# config action for admin
config.actions do
# root actions
dashboard do # mandatory
i18n_key :dash
end
# collection actions
index # mandatory
new
export
history_index
bulk_delete
confirm_users
# member actions
show
edit
delete
history_show
show_in_app
end
end
# located at #{Rails.root}/lib/rails_admin_confirm_users.rb
require 'rails_admin/config/actions'
require 'rails_admin/config/actions/base'
module RailsAdminConfirmUsers
end
module RailsAdmin
module Config
module Actions
class ConfirmUsers < RailsAdmin::Config::Actions::Base
RailsAdmin::Config::Actions.register(self)
register_instance_option :collection do
true
end
register_instance_option :link_icon do
'icon-check'
end
register_instance_option :controller do
Proc.new do
@objects.each do |user|
user.confirm!
end
end
flash[:notice] = "You have confimed for #{@objects.length} users."
redirect_to back_or_index
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment