dimanche 27 janvier 2019

Ransack on enum filter for dropdown list

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>
.......

Aucun commentaire:

Enregistrer un commentaire