How to use the Countries gem

北城以北 提交于 2019-12-03 08:17:41

1) You don't need a new controller/model to access the countries

2) There is an example app on the README page which shows you how to use forms and dropdowns.

3) The countries are stores within the app. I believe country_select includes the ISO 3166 gem to get the list of countries. You can view the data in the countries.yaml file

If want to know anything else, I recommend looking at the example app. It provides a good example of how to use the gem.

You do not need to create a new controller/model to work with the gem.

In order for you to create dropdown, just install the country_select gem (as stated in the doc)

Then to use it, just do that in your views:

country_select(:your_model_name, :your_attribute_name)

To integrate it in a form_for with some extra params like Bootstrap classes or default country selected:

<%= form_for @message, url: contact_path, html: { :class => "form-horizontal " } do |f| %>

    <div class="form-group">
        <%= f.label :country, :class => "col-md-3 control-label" %>
        <div class="col-md-9">
            <%= f.country_select :country, ["United States"], {}, { :class => "form-control" } %>
        </div>
    </div>

    <%= f.submit "Submit", :class => "btn btn-default" %>

<% end %>

For the exact options you have w/ this method, see here:

country_select(method, priority_or_options = {}, options = {}, html_options = {})

Hope it helps !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!