使用country_select gem的Rails搜索模型

时间:2016-02-15 06:39:27

标签: ruby-on-rails

我正在使用country_code gem并设法将country_name转换为index.html.erb中的Search

现在,我创建了一个country_code模型,我只能使用country_namecountry_name。知道如何转换这种方式用户可以选择country_code,但发送参数仍然是class SearchesController < ApplicationController def new @search = Search.new @country = Property.uniq.pluck(:country_code) end end

searches.controller.rb

<%= form_for @search, html: {class: "pure-form"} do |f| %>
   <div class="field">
    <%= f.label "Country" %>
    <%= f.select :country, options_for_select(@country), :include_blank => true%>
   </div>

  <div class="actions"><%= f.submit "Search", class: "btn" %></div>

<% end %>

new.html.erb

copy <TABLE> FROM <FILE> with DELIMITER = '\t' AND NULL = 'NULL' AND QUOTE = '\"' AND ESCAPE = '\\';

1 个答案:

答案 0 :(得分:0)

您可以仅使用:限制国家/地区。

@limit_country = Property.pluck(:country).uniq

<%= form_for @search, html: {class: "pure-form"} do |f| %>
   <div class="field">
    <%= f.label "Country" %>
    <%= f.country_select :country, only: @limit_country, include_blank: true
   </div>

  <div class="actions"><%= f.submit "Search", class: "btn" %></div>

<% end %>