carmen-rails
Rails プロジェクトで gemを使用したいのですが、 githubのドキュメントでは使用方法がよくわかりません。たとえば、ユーザーに国と州を持たせたい場合:
まず、ユーザー モデル (国と州) に2 つの列を追加する必要があります。
2番目:選択した国と州をユーザーフォームに追加します:
<%= simple_form_for @user do |f| %>
<div class="field">
<%= f.label :country_code %><br />
<%= f.country_select :country_code, priority: %w(US CA), prompt: 'Please select a country' %>
</div>
<div class="field">
<%= f.label :state_code %><br />
<%= render partial: 'subregion_select', locals: {parent_region: f.object.country_code} %>
</div>
<% end %>
次に、私のパーシャルは次のようになります。
<div id="order_state_code_wrapper">
<% parent_region ||= params[:parent_region] %>
<% country = Carmen::Country.coded(parent_region) %>
<% if country.nil? %>
<em>Please select a country above</em>
<% elsif country.subregions? %>
<%= subregion_select(:order, :state_code, parent_region) %>
<% else %>
<%= text_field(:order, :state_code) %>
<% end %>
私は正しい ?
フォームが送信されたときに国と州を検証する方法は?
最後に、選択フォームで国と州の言語を変更する方法(たとえばフランス語に)?