试图让carmen_rails启动并运行以将国家和子区域(州)添加到我的家庭用户注册中并遇到一个问题我在任何在线搜索中都没有得到任何帮助(至少从我能找到的内容).
安装
gem 'carmen-rails', '~> 1.0.0'
Run Code Online (Sandbox Code Playgroud)
遵循github说明(https://github.com/jim/carmen-rails),应将以下代码插入我的注册页面:
<%= simple_form_for @user do |f| %>
<%= f.input :country_code do %>
<%= f.country_select :country_code, {object: f.object, prompt: 'Country'} %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我目前正在使用Rails 4.0.0和Bootstrap 3 RC2,因此我的注册码看起来像这样(以及标准表单设置):
<div class="form-group">
<%= f.label :country, class: "col-md-4 control-label" %>
<div class="col-md-8">
<%= f.country_select :country, {priority: %w(US CA), prompt: "Please select a country", class: "form-control"} %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
来自app/models/user.rb的验证部分
validates :country, presence: true
validates :subregion, presence: true
Run Code Online (Sandbox Code Playgroud)
我得到下面的错误,无法找出根本原因或解决方案.任何帮助是极大的赞赏!
wrong number of arguments (3 …Run Code Online (Sandbox Code Playgroud) 我正在使用Carmen gem在Rails中渲染一个国家/地区.该国家/地区作为代码存储在数据库中.如何从此代码中获取"全名"?
宝石'carmen-rails','〜> 1.0.0.beta3'
<%= f.country_select :country, prompt: 'Please select a country' %>
Run Code Online (Sandbox Code Playgroud)
我尝试了几种选择,到目前为止还没有一种方法可行!例如:
Carmen::country_name(@profile.country)
Run Code Online (Sandbox Code Playgroud)
导致错误:
卡门的未定义方法`country_name':模块
第二次尝试:
在profiles_controller中:
@profile = Profile.find(params[:id])
@country = Carmen::Country.named( @profile.country )
Run Code Online (Sandbox Code Playgroud)
在配置文件索引视图中
<%= @country.official_name %>
Run Code Online (Sandbox Code Playgroud)
这会导致错误:
未命名的方法`official_name'代表nil:NilClass
为什么我的应用程序失败了?
我正在使用carmen rails gem来选择国家和次区域.实施数据库后保存国家代码和子区域代码.
我可以使用此代码从代码中获取国家名称@country_name = Carmen::Country.coded(country_code)
现在我想从子区域代码获取子区域名称.
帮我解决这个问题.