https://github.com/shioyama/mobility-ransack
Search attributes translated by Mobility with Ransack
https://github.com/shioyama/mobility-ransack
i18n rails ransack ruby translation
Last synced: 3 months ago
JSON representation
Search attributes translated by Mobility with Ransack
- Host: GitHub
- URL: https://github.com/shioyama/mobility-ransack
- Owner: shioyama
- License: mit
- Created: 2018-09-12T03:39:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T06:48:14.000Z (over 2 years ago)
- Last Synced: 2025-03-15T02:39:28.282Z (3 months ago)
- Topics: i18n, rails, ransack, ruby, translation
- Language: Ruby
- Size: 70.3 KB
- Stars: 29
- Watchers: 3
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Mobility Ransack
================[][gem]
[][actions]
[][codeclimate][gem]: https://rubygems.org/gems/mobility-ransack
[actions]: https://github.com/shioyama/mobility-ransack/actions
[codeclimate]: https://codeclimate.com/github/shioyama/mobility-ransackSearch on translated attributes with
[Mobility](https://github.com/shioyama/mobility) and
[Ransack](https://github.com/activerecord-hackery/ransack).## Installation
Just add the gem to your Gemfile:
```ruby
gem 'mobility-ransack', '~> 1.2.2'
```Now enable the `ransack` plugin in Mobility's configuration:
```ruby
Mobility.configure do
plugins do
ransack# ...
end
end
```This will enable the ransack plugin for all models. Disable it by passing
`false` to the `ransack` option:```ruby
class Post < ApplicationRecord
extend Mobility
translates :foo, ransack: false
end
```You can search on `foo` with Ransack just like any untranslated attribute, e.g.
if `Post` has a `title` attribute translated with the Jsonb backend:```ruby
Post.ransack(title_cont: "foo").result
#=> SELECT "posts".* FROM "posts" WHERE ("posts"."title" ->> 'en') ILIKE '%foo%'
```Other backends work exactly the same way.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).