-
-
Save nfabian13/1142b8712bf0f7ab7abd to your computer and use it in GitHub Desktop.
Revisions
-
justinweiss revised this gist
Feb 24, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ module ClassMethods # URL params. Make sure you don't pass stuff directly from the web without # whitelisting only the params you care about first! def filter(filtering_params) results = self.where(nil) # create an anonymous scope filtering_params.each do |key, value| results = results.public_send(key, value) if value.present? end -
justinweiss revised this gist
Feb 18, 2014 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,15 @@ # Call scopes directly from your URL params: # # @products = Product.filter(params.slice(:status, :location, :starts_with)) module Filterable extend ActiveSupport::Concern module ClassMethods # Call the class methods with the same name as the keys in <tt>filtering_params</tt> # with their associated values. Most useful for calling named scopes from # URL params. Make sure you don't pass stuff directly from the web without # whitelisting only the params you care about first! def filter(filtering_params) results = self filtering_params.each do |key, value| -
justinweiss created this gist
Feb 18, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ module Filterable extend ActiveSupport::Concern module ClassMethods def filter(filtering_params) results = self filtering_params.each do |key, value| results = results.public_send(key, value) if value.present? end results end end end