Last active
June 14, 2016 07:56
-
-
Save groony/b8a8f15cc4f592fc8380 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ExtendedActionItems | |
private | |
def add_default_action_items | |
super | |
add_default_toggle_filter_action_item | |
end | |
def add_default_toggle_filter_action_item | |
add_action_item :filter, only: :index do | |
link_to I18n.t('active_admin.filter_button'), '#', class: 'filter_button' | |
end | |
end | |
end | |
module ActiveAdmin | |
module ViewHelpers | |
include ApplicationHelper | |
end | |
class ResourceController < BaseController | |
before_action :patch_params, only: :index | |
after_action :store_location, only: :index | |
QUERY_DATE_FIELDS = %i(created_at updated_at last_visit_at) | |
def patch_params | |
return unless params[:q].present? | |
QUERY_DATE_FIELDS.each do |field| | |
field_lteq = "#{field}_lteq" | |
next unless params[:q][field_lteq.to_sym].present? | |
params[:q][field_lteq.to_sym] = send(field_lteq) | |
end | |
end | |
QUERY_DATE_FIELDS.each do |field| | |
field_lteq = "#{field}_lteq" | |
define_method(field_lteq) do | |
params[:q][field_lteq.to_sym].to_date.end_of_day | |
end | |
end | |
def store_location | |
session[:return_to] = request.get? ? request.original_url : request.referer | |
end | |
def redirect_back(*options) | |
tag_options = {} | |
options.first.each { |k, v| tag_options[k] = v } unless options.empty? | |
path = session.delete(:return_to) || :back | |
redirect_to path, tag_options | |
end | |
end | |
class Resource | |
prepend ExtendedActionItems | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment