Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Build filter forms easily by using ransack
and simple_form
.
Add this line to your application's Gemfile:
gem 'filter_form'
And then execute:
$ bundle
Or install it yourself as:
$ gem install filter_form
In your contoller:
def index
@q = Person.search(params[:q])
@people = @q.result
end
In your view file:
<%= filter_form_for @q do |f| %>
<%= f.filter_input :married # boolean %>
<%= f.filter_input :name # string %>
<%= f.filter_input :age # integer %>
<%= f.filter_input :birthday # date %>
<%= f.filter_input :city # belongs_to %>
<%= f.filter_input :parents # has_many %>
<%= f.filter_input :amount # money %>
<%= f.filter_input :gender, as: :check_boxes, collection: [[:male, 'Male'], [:female, 'Female']] # checkboxes %>
<%= f.button :submit %>
<% end %>
Mapping | Database Column Type | Default predicate | Generated HTML Element |
--------------- |:------------------------------------------------|:----------------------|:--------------------------|
`boolean` | `boolean` | `true` | `input[type="checkbox"]` |
`string` | `string` | `cont` | `input[type="text"]` |
`text` | `text` | `cont` | `input[type="text"]` |
`integer` | `integer` | `eq` | `input[type="number"]` |
`float` | `float` | `eq` | `input[type="number"]` |
`decimal` | `decimal` | `eq` | `input[type="number"]` |
`date` | `date` | `eq` | `input[type="text"]` |
`datetime` | `datetime` | `eq` | `input[type="text"]` |
`select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations | `eq` | `select` |
`money` | [monetized](https://github.com/RubyMoney/money-rails) attribute | `eq` | `input[type="number"]` |
`check_boxes` | `any' | `in` | `input[type=checkbox]` |
`radio_buttons` | `any' | `eq` | `input[type=radio]` |
<%= filter_form_for @q do |f| %>
<%= f.filter_input :year, as: :select, collection: (2000..2013).to_a, predicate: :not_eq %>
<%= f.button :submit %>
<% end %>
You can show predicate selector:
<%= filter_form_for @q do |f| %>
<%= f.filter_input :id, predicate_selector: [['=', 'eq'], ['>', 'gt'], ['<', 'lt']] %>
<%= f.button :submit %>
<% end %>
To filter by monetized attribute please add to your controller:
class ApplicationController < ActionController::Base
include FilterForm::MoneyConverter
...
end
You can wrap your select in select2
:
<%= filter_form_for @q do |f| %>
<%= f.filter_input :title, as: :select, in: :select2 %>
<%= f.button :submit %>
<% end %>
If you want to use predicate selector, jQuery Datepicker for date
and datetime
automatically or Select2, add to your application.js file:
//= require jquery
//= require jquery.ui.datepicker
//= require select2
//= require filter_form
And application.css:
*= require jquery.ui.datepicker
*= require select2
*= require filter_form
For more information about predicates visit ransack.
If you want to customize your form visit simple_form.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that filter_form demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.