Skip to content

Instantly share code, notes, and snippets.

View developer88's full-sized avatar

Andrey Eremin developer88

View GitHub Profile
@developer88
developer88 / some_active_admin_resource.rb
Created March 5, 2013 13:49
Add custom method to export table as CSV file for ActiveAdmin Resource + scope items from filter + save csv file compatible with Russian Microsoft Office Excel
filter :reception_reception_date, as: :date_range, label: Reception.human_attribute_name(:reception_date_full)
collection_action :download_report, :method => :get do
services = Service.includes(:order, reception: [{medic: :clinic_medics}]).where{ orders.orderable_id != nil } # necessary model
if params[:q] && params[:q][:reception_reception_date_gte].length > 1
services = services.where("receptions.reception_date >= ?", params[:q][:reception_reception_date_gte])
end
if params[:q] && params[:q][:reception_reception_date_lte].length > 1
services = services.where("receptions.reception_date < ?", params[:q][:reception_reception_date_lte])
end
@developer88
developer88 / in_some_active_admin_resource.rb
Created March 4, 2013 15:43
Ugly hack to display error messages in ActiveAdmin form
if f.object.errors.size > 0
f.inputs I18n.t("active_admin.errors") do
content_tag(:li, f.object.errors.full_messages.join('<br/>').html_safe, class: 'errors_messages')
end
end
@developer88
developer88 / some_recource.rb
Created February 28, 2013 10:55
Add custom header for has_many form in Active Admin
# in any ActiveAdmin Resource you need in form block add the following code
# change 'translations' with your association name
f.has_many :translations do |translation|
translation.inputs("Caption"){} # Adding caption for languages
translation.inputs(""){} # Spacer
translations.input # add necessary inputs here
end
@developer88
developer88 / active_admin.rb
Last active March 19, 2016 20:18
This is my gist that show how we can use CanCan with ActiveAdmin and store permissions in database.
# config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
config.current_user_method = :current_user
config.authentication_method = :authenticate_user!
config.before_filter :admin_role_filter
end
# Adding all recource names to Permissions table after ActiveAdmin is loaded
@developer88
developer88 / collection_decorator.rb
Created January 16, 2013 12:21
Fix problem with Pagination's Gem for Rails and Draper and Kaminari gem
# This is a dirty hack to fix Draper problem with kaminari
# Put this in app/decorators/collection_decorator.rb
class Draper::CollectionDecorator
delegate :current_page, :total_pages, :limit_value
def total_count
source.total_count
end