首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Carmen Rails- Devise -Rails4: country_code问题

Carmen Rails- Devise -Rails4: country_code问题
EN

Stack Overflow用户
提问于 2013-12-04 20:52:19
回答 1查看 265关注 0票数 0

我是新人,我有一个基本的问题

在使用carmen-rails和Rails4使用devise创建新用户时,country_code和states_code无法通过

允许使用country_code和state_code

以下是我的代码:

在设计注册中:

代码语言:javascript
复制
= f.label :country_code 
= f.country_select :country_code, {priority: %w(US CA), prompt: "Please select your country"}, :style => "width:170px;float:left;font-size:14px;", :type => 'text'
= f.label :state_code
= render partial: '/users/subregion_select', locals: {parent_region: f.object.country_code}

在用户/子区域中选择:

代码语言:javascript
复制
<% parent_region ||= params[:parent_region] %> <% unless parent_region.nil? %>
<% country = Carmen::Country.coded(parent_region) %> 
<% end %>

<% if country.nil? %>
Please select a country above
<% elsif country.subregions? %>
<%= f.subregion_select(:user, :state_code, parent_region) %>
<% else %>
<%= text_field(:user, :state_code) %>
<% end %>

在users.js.coffee中

代码语言:javascript
复制
$('select#user_country_code').change (event) ->
select_wrapper = $('#user_state_code_wrapper')

$('select', select_wrapper).attr('disabled', true)

country_code = $(this).val()

url = "/users/subregion_options?parent_region=#{country_code}"
select_wrapper.load(url)

在routes.rb中

代码语言:javascript
复制
get '/users/subregion_options' => 'users#subregion_options'

在用户控制器中:

代码语言:javascript
复制
def subregion_options
render partial: 'subregion_select'
end

在我的控制台上,所有的数据都被保存了,除了country_code: nil (即使我放了美国),当我选择一个国家时,states_code不会生成。

是因为我需要使用Formstatic吗?

感谢您的帮助:)

EN

回答 1

Stack Overflow用户

发布于 2014-04-24 05:25:17

看起来像是Devise卫生设施的问题。

代码语言:javascript
复制
#application_controller

def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| 
         u.permit(:email, 
                  :password, 
                  :password_confirmation, 
                  :first_name, 
                  :last_name, 
                  :street1, 
                  :street2, 
                  :city,
                  :state, 
                  :zipcode, 
                  :country_code) 
 }

试一试吧!

干杯

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20375927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档