Reputation: 77
class Schedule < ApplicationRecord
belongs_to :event
enum county: {USA: 0, INDIA: 1, Brasil: 2}
end
ransack select in index.erb.html
<%= f.collection_select :schedules_county_matches_all, Schedule.counties.map{ |dp| [dp.first, dp.first.humanize] }, :first.to_s, :second ,:include_blank => "All"%>
which gives output select dropdown list but not value as in Postgres database the value stored as integer not string
<li class=""><span>All</span></li>
<li class=""><span>USA</span></li>
.......
As working filter, I guess in view it should be added value in li
<li value=""><span>All</span></li>
<li value="0"><span>USA</span></li>
.......
Upvotes: 0
Views: 1220
Reputation: 1308
<%= f.select :schedules_county_eq, options_for_select(Schedule.counties), include_blank: 'All' %>
Rails 7, Ransack 2.5.0. Lowercase strings.
Upvotes: 0
Reputation: 4734
Create your ransacker.
# user.rb
enum role: [:Admin, :Analyst]
ransacker :role, formatter: proc {|v| roles[v]} do |parent|
parent.table[:role]
end
And then add the field in your index.html.erb
<%= f.select :role_eq, User.roles.keys , {:include_blank => 'All Roles'}, { :class => 'form-control' } %>
Upvotes: 0
Reputation: 384
Use below line code for your problem
<%= f.select :schedules_county_matches_all, Schedule.counties.map { |r| [r[0], r[1].to_i] }, include_blank: true %>
Upvotes: 1