-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1928 from Daxter/1093-dropdown-for-habtm
[1093] HABTM Select Filters
- Loading branch information
Showing
9 changed files
with
127 additions
and
97 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module ActiveAdmin | ||
module Filters | ||
module FormtasticAddons | ||
|
||
# | ||
# The below are Formtastic overrides to use `base` instead of `class` for MetaSearch. | ||
# | ||
|
||
# Returns the default label for a given attribute. Uses ActiveModel I18n if available. | ||
def humanized_method_name | ||
if object.base.respond_to?(:human_attribute_name) | ||
object.base.human_attribute_name(method) | ||
else | ||
method.to_s.send(builder.label_str_method) | ||
end | ||
end | ||
|
||
# Returns the association reflection for the method if it exists | ||
def reflection_for(method) | ||
@object.base.reflect_on_association(method) if @object.base.respond_to?(:reflect_on_association) | ||
end | ||
|
||
# Returns the column for an attribute on the object being searched if it exists. | ||
def column_for(method) | ||
@object.base.columns_hash[method.to_s] if @object.base.respond_to?(:columns_hash) | ||
end | ||
|
||
# | ||
# The below are custom methods that Formtastic does not provide. | ||
# | ||
|
||
def foreign_key?(method) | ||
@object.base.reflections.select{ |_,r| r.macro == :belongs_to }.values | ||
.map(&:foreign_key).include? method.to_s | ||
end | ||
|
||
def polymorphic_foreign_type?(method) | ||
type = Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 0 ? proc{ |r| r.options[:foreign_type] } : :foreign_type | ||
@object.base.reflections.values.select{ |r| r.macro == :belongs_to && r.options[:polymorphic] } | ||
.map(&type).include? method.to_s | ||
end | ||
|
||
end | ||
end | ||
end |
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
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
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
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
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