app/models/concerns/fae/base_model_concern.rb in fae-rails-1.3.0 vs app/models/concerns/fae/base_model_concern.rb in fae-rails-1.3.1
- old
+ new
@@ -7,10 +7,19 @@
included do
include Fae::Trackable if Fae.track_changes
end
+ def fae_nested_parent
+ # override this method in your model
+ end
+
+ def fae_nested_foreign_key
+ return if fae_nested_parent.blank?
+ "#{fae_nested_parent}_id"
+ end
+
module ClassMethods
def fae_display_field
# override this method in your model
end
@@ -40,17 +49,29 @@
# override this method in your model
for_fae_index
end
def fae_search(query)
- all.to_a.keep_if { |i| i.fae_display_field.present? && i.fae_display_field.downcase.include?(query.downcase) }
+ all.to_a.keep_if { |i| i.fae_display_field.present? && i.fae_display_field.to_s.downcase.include?(query.downcase) }
end
def to_csv
CSV.generate do |csv|
csv << column_names
all.each do |item|
csv << item.attributes.values_at(*column_names)
+ end
+ end
+ end
+
+ def translate(*attributes)
+ attributes.each do |attribute|
+ define_method attribute.to_s do
+ self.send "#{attribute}_#{I18n.locale}"
+ end
+
+ define_singleton_method "find_by_#{attribute}" do |val|
+ self.send("find_by_#{attribute}_#{I18n.locale}", val)
end
end
end
end