ruby on rails - Creating a input that is dependent on another -



ruby on rails - Creating a input that is dependent on another -

i want associate place activity, place has next fields: country city, adress , name. want like, take country , city, there appear (in dropdown) places have belong city, there anyway how can that? main problem variable :city_name, know cant create variables in views this, dont know how , how temporarily save it... help appreciated :)

this code doesn't work, prototype want do:

<%= form_for @activity, :html => { :class => "form-horizontal activity" } |f| %> <div class="transbox"> <h1><%= "add place activity" %></h1> </div> <div class = "box_round"> <div class="row"> <div class="control-group col-lg-10"> <%= f.label "city name", :class => 'control-label' %> <div class="controls"> //variable :city_name not exist <%= f.text_field :city_name, :class => 'form-control' %> </div> <%= error_span(@activity[:resume]) %> </div> <% if !:city_name.nil? %> <div class="control-group col-lg-10"> <%= f.label "city name", :class => 'control-label' %>s <div class="controls"> <% place_options = options_from_collection_for_select(@places.where(:city => :city_name).sort { |a,b| a.name <=> b.name }, :id, :name, selected: params[:place_id]) %> <%= f.select(:place_id, place_options, {prompt: 'select sport'}, {prompt: 'select place', include_blank: false, class: "place" }) %> <%= link_to "place doesn't exist yet?" , new_place_path %> </div> <%= error_span(@activity[:resume]) %> </div> <% end %> </div> </div> </div> <% end %>

what looking called ajax request. bit much code out you, gist of is:

write js watcher @ country field. on country field change, create js phone call server , say: "give me cities in country" return js takes list of cities , overwrites available options in city's dropdown field.

you may take same places well, concept/idea same. reference fun, check out railscast: http://railscasts.com/episodes/136-jquery-ajax-revised

ruby-on-rails

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -