0
我想將地點與某個活動相關聯,地點包含以下字段:一個國家,一個城市,一個地址和一個名稱。我想做一些類似的事情,只要你選擇了一個只有意願的國家和一個城市,那麼只會出現(在下拉菜單中)那些屬於那個城市的地方,無論如何,我該怎麼做?我的主要問題是變量:city_name,我知道我不能在這樣的視圖中創建變量,但我真的不知道該怎麼做,以及如何暫時保存它...任何幫助將不勝感激:)創建依賴於另一個的輸入
此代碼不起作用,它只是我想要做的原型:
<%= 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 %>