I want associate a Place to an Activity, a Place has the following fields: a country a city, a adress and a name. I want to do something like, as soon as you choose a country the will only and a city, there will only appear (in a dropdown) the Places that have that belong to that city, is there anyway how i can do that? My main problem is the variable :city_name, i know i cant create variables in views like this, but i really dont know how to do it and also how to temporarily save it... Any help would be appreciated :)
This code doesn't work, its just a prototype from what i want to do:
<%= form_for @activity, :html => { :class => "form-horizontal activity" } do |f| %>
<div class="transbox">
<h1><%= "Add Place To 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 does 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 %>