0
我是Ruby on Rails編程語言的新手。我想顯示一個動態下拉菜單。這裏是我的代碼:如何在Ruby on Rails中使用動態選項創建選擇標籤?
控制器
def property
@rental_types = RentalType.all
end
意見
<%= form_tag(@property, method: "post", class: 'form-horizontal form-label-left', multipart: true, novalidate:"") do %>
<%= select :property, :type_id, options_for_select(@rental_types.collect { |type|
[type.type_name.titleize, type.id] }, 1), {}, { id: 'countries_select', class: 'form-control col-md-7 col-xs-12' } %>
<% end %>
我的輸出應該
<select name="property[type_id]" class="form-control col-md-7 col-xs-12" id="countries_select">
<option value="10">1 Bedroom Rentals</option>
<option value="11">2 Bedroom Rentals</option>
<option value="12">3 Bedroom Rentals</option>
<option value="13">4 Bedroom Rentals</option>
</select>
我想在我的視圖頁面動態下拉列表。但我得到undefined method 'type_id' for #<User:0x7aff460>
錯誤消息。
請幫幫我。
提示無法正常工作。你可以請檢查'提示:'選擇人' – Chinmay235