-
-
Notifications
You must be signed in to change notification settings - Fork 829
Create aliases for (long) search fields #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
82e19ba
afa3faf
5ce791a
383d241
90b34ce
4a0193b
c44e109
7119d71
e483959
7bf08ad
7f8aba8
cb72305
b4556ff
e903b4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,13 @@ module ActionView::Helpers::Tags | |
class Base | ||
private | ||
def value(object) | ||
object.send @method_name if object # use send instead of public_send | ||
search_attr = @method_name.to_s.sub(/_#{Ransack::Predicate.detect_from_string(@method_name.to_s)}$/, Ransack::Constants::EMPTY) | ||
|
||
search_pred = @method_name.to_s.sub(/^#{search_attr}_/, Ransack::Constants::EMPTY) | ||
|
||
if object.klass._ransacker_aliases.has_key?(search_attr) | ||
object.send "#{object.klass._ransacker_aliases[search_attr]}_#{search_pred}" if object | ||
|
||
else | ||
|
||
object.send @method_name if object # use send instead of public_send | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,6 +335,12 @@ def self.sane_adapter? | |
expect { s.result.first }.to_not raise_error | ||
end | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace detected. |
||
describe '#ransack_alias' do | ||
s1 = Person.ransack(cmnt_bd_cont: "some_words") | ||
s2 = Person.ransack(comments_body_cont: "some_words") | ||
expect(s1.result.to_sql).to eq(s2.result.to_sql) | ||
end | ||
|
||
describe '#ransackable_attributes' do | ||
context 'when auth_object is nil' do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,8 @@ class Person < ActiveRecord::Base | |
SQL | ||
Arel.sql(query) | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace detected. |
||
ransacker_alias :cmnt_bd, :comments_body | ||
|
||
def self.ransackable_attributes(auth_object = nil) | ||
if auth_object == :admin | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.