module ActiveAdminSimpleLife::SimpleElements
Public Instance Methods
filter_for_main_fields(klass, options ={})
click to toggle source
it check only for gender field for now
# File lib/active_admin_simple_life/simple_elements.rb, line 41 def filter_for_main_fields(klass, options ={}) klass.main_fields.each do |f| if f == :gender filter ExtensionedSymbol.new(f).cut_id, collection: genders else filter ExtensionedSymbol.new(f).cut_id end end end
form_for_main_fields(klass, options={}, &block)
click to toggle source
# File lib/active_admin_simple_life/simple_elements.rb, line 51 def form_for_main_fields(klass, options={}, &block) form do |f| f.semantic_errors(*f.object.errors.keys) f.inputs do klass.main_fields.each do |ff| ff_cut_id = ExtensionedSymbol.new(ff).cut_id current_options = options[ff] || options[ff_cut_id] || {} if ff == ff_cut_id f.input ff_cut_id else f.input ff_cut_id, {as: :select, member_label: :to_s}.merge(current_options) end end f.instance_eval(&block) if block_given? end f.actions end end
index_for_main_fields(klass, options = {})
click to toggle source
# File lib/active_admin_simple_life/simple_elements.rb, line 6 def index_for_main_fields(klass, options = {}) max_length = options[:max_length] add_fields = [options[:add]].flatten.compact position = options[:position] index download_links: false do selectable_column id_column klass.main_fields.insert(position, *add_fields).each do |symbol| column(I18n.t("activerecord.attributes.#{klass.to_s.underscore}.#{symbol}"), sortable: symbol) do |current| plural_symbol = symbol.to_s.pluralize field_value = current.send(ExtensionedSymbol.new(symbol).cut_id) case field_value when ActiveRecord::Base link_to truncate_field(field_value, max_length), send(fetch_path(field_value), field_value.id) when ::ActiveSupport::TimeWithZone, Time, Date I18n.l field_value, format: :long when TrueClass span_true when FalseClass span_false else if klass.respond_to?(plural_symbol) field_value && I18n.t("activerecord.attributes.#{klass.underscore}.#{plural_symbol}.#{field_value}") else truncate_field field_value.to_s, max_length end end end end actions end end
nested_form_for_main_fields(klass, nested_klass, options={})
click to toggle source
simple nested set for 2 classes with defined main_fields
# File lib/active_admin_simple_life/simple_elements.rb, line 71 def nested_form_for_main_fields(klass, nested_klass, options={}) form_for_main_fields(klass,options) do |form_field| nested_table_name = nested_klass.to_s.underscore.pluralize.to_sym main_model_name = klass.to_s.underscore.to_sym form_field.has_many nested_table_name, allow_destroy: true do |form| nested_klass.main_fields.map { |f| ExtensionedSymbol.new(f).cut_id }.each do |nested_field| current_options = options.fetch(nested_table_name){{}}.fetch(nested_field){{}} form.input(nested_field, current_options) unless nested_field == main_model_name end end end end