class Acts::DataTable::ScopeFilters::FormHelper
Public Class Methods
field_id(group, scope, arg)
click to toggle source
@return [String] A generated DOM id for the given group, scope and arg
# File lib/acts_as_data_table/scope_filters/form_helper.rb, line 48 def self.field_id(group, scope, arg) [group, scope, arg].map(&:to_s).join('_') end
field_name(arg)
click to toggle source
@return [String] A generated field name for the given arg to be used in filter forms
# File lib/acts_as_data_table/scope_filters/form_helper.rb, line 41 def self.field_name(arg) "scope_filters[args][#{arg}]" end
new(action_view, group, scope)
click to toggle source
# File lib/acts_as_data_table/scope_filters/form_helper.rb, line 5 def initialize(action_view, group, scope) @action_view = action_view @group = group.to_s @scope = scope.to_s end
Public Instance Methods
active?()
click to toggle source
@return [TrueClass, FalseClass] true
if the current filter is currently active
# File lib/acts_as_data_table/scope_filters/form_helper.rb, line 20 def active? @action_view.acts_as_data_table_session.active_filter(@group) == @scope end
errors()
click to toggle source
@return [Array] Filter validation errors on the current group
# File lib/acts_as_data_table/scope_filters/form_helper.rb, line 34 def errors @action_view.acts_as_data_table_session.errors_on(@group) end
remove_url()
click to toggle source
@return [String] The URL to remove the current filter group from the active filters
# File lib/acts_as_data_table/scope_filters/form_helper.rb, line 27 def remove_url @action_view.url_for({:scope_filters => {:action => 'remove', :group => @group}}) end
text_field(arg, options = {})
click to toggle source
# File lib/acts_as_data_table/scope_filters/form_helper.rb, line 11 def text_field(arg, options = {}) value = options.delete(:value) || current_arg(arg) options[:id] = FormHelper.field_id(@group, @scope, arg) @action_view.text_field_tag(FormHelper.field_name(arg), value, options) end
Private Instance Methods
current_arg(arg)
click to toggle source
Retrieves the current value for the given arg name from the session. Also searches the current request’s params if the arg couldn’t be found in the session. This is useful to keep given values in case of validation errors.
# File lib/acts_as_data_table/scope_filters/form_helper.rb, line 59 def current_arg(arg) Acts::DataTable.lookup_nested_hash(@action_view.acts_as_data_table_session.active_filters, @group, @scope.to_s, arg.to_s) || Acts::DataTable.lookup_nested_hash(@action_view.params, :scope_filters, :args, arg) end