Created
January 29, 2017 05:48
-
-
Save acro5piano/b5a8962fb85c57b4566da1db712ac475 to your computer and use it in GitHub Desktop.
Ransackで A and (B or C) ref: http://qiita.com/acro5piano/items/9f792d58f0647892d612
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 characters
SELECT "users".* FROM "users" | |
WHERE ("users"."name" ILIKE '%山田%' | |
AND ("users"."email" ILIKE '%gmail.com%' | |
OR "users"."address" ILIKE '%東京都%')) |
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 characters
= search_form_for @q do |f| | |
= f.search_field :name_cont | |
= f.grouping_fields do |g| | |
= g.hidden_field :m, value: 'or' | |
= g.search_field :email_cont | |
= g.search_field :address_cont |
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 characters
def index | |
@q = User.search(params[:q])) | |
@q.build_grouping unless @q.groupings.any? | |
@users = @q.result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment