Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flexoid/mongoid_filter
https://github.com/flexoid/mongoid_filter
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/flexoid/mongoid_filter
- Owner: flexoid
- License: mit
- Created: 2013-04-03T13:04:38.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-04-11T22:41:44.000Z (almost 12 years ago)
- Last Synced: 2024-03-14T23:46:24.987Z (10 months ago)
- Language: Ruby
- Size: 139 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# MongoidFilter
TODO: Write a gem description
## Installation
Add this line to your application's Gemfile:
gem 'mongoid_filter'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mongoid_filter
## Usage
### Example
#### Model
```ruby
class Log
include Mongoid::Document
include MongoidFilterfield :event_type, type: String
field :status, type: Boolean# It will allow us to filter by this three fields
can_filter_by :event_type, :status, :created_at# Specify custom method to create object from params
special_filter :created_at, ->(date) { Date.strptime(date, '%m/%d/%Y') }
end
```
#### Controller
```ruby
@logs = Log.where(user_id: user.id).filter_by(params[:search])
```#### View
```erb
<%= form_for @request_logs.filter_form_object, as: :search do |f| %>
<%= f.select :event_type_eq, Log.event_types %>
<%= f.select :status_eq, Log.statuses %>
<%= f.text_area :created_at_gt %>
<% end %>
```## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request