Ruby on Rails Populate second dropdown based on 1st dropdown's selection -
currently, have dropdown (<options>
) pulling list of states in database, , want sec dropdown appear , provide list of cities associated state 1 time first dropdown selected.
here samples of files have provide clarification:
models/states.rb:
class states < activerecord::base has_many :cities end
models/cities.rb:
class city < activerecord::base belongs_to :state # states referenced table column state_id end
inside of view i'm working with, have this:
<div class="field"> <%= f.label :state_id %><br> <%= select(:city, :state_id, state.all.collect {|c| [c.name, c.id]}, {prompt: "select state"}) %> </div>
but of course of study populates first dropdown. there easy way accomplish goal using ruby on rails helpers? or have utilize ajax , jquery?
ruby-on-rails ruby
No comments:
Post a Comment