... | @@ -8,11 +8,11 @@ First you have to define a new ransacker in the model you want to apply the filt |
... | @@ -8,11 +8,11 @@ First you have to define a new ransacker in the model you want to apply the filt |
|
|
|
|
|
```ruby
|
|
```ruby
|
|
ransacker :country,
|
|
ransacker :country,
|
|
formatter: proc { |country|
|
|
formatter: proc { |country|
|
|
results = Order.find_by_country(country).map(&:id)
|
|
results = Order.find_by_country(country).map(&:id)
|
|
results = results.present? ? results : nil
|
|
results = results.present? ? results : nil
|
|
}, splat_params: true do |parent|
|
|
}, splat_params: true do |parent|
|
|
parent.table[:id]
|
|
parent.table[:id]
|
|
end
|
|
end
|
|
```
|
|
```
|
|
|
|
|
... | @@ -20,11 +20,11 @@ Then you have to define the actual code that will do the filter: |
... | @@ -20,11 +20,11 @@ Then you have to define the actual code that will do the filter: |
|
|
|
|
|
```ruby
|
|
```ruby
|
|
def self.find_by_country(country_name)
|
|
def self.find_by_country(country_name)
|
|
Order.where(
|
|
Order.where(
|
|
"shipping_address @> hstore(:key, :value)",
|
|
"shipping_address @> hstore(:key, :value)",
|
|
key: "country",
|
|
key: "country",
|
|
value: country_name
|
|
value: country_name
|
|
)
|
|
)
|
|
end
|
|
end
|
|
```
|
|
```
|
|
|
|
|
... | | ... | |