我是新人,我有一个基本的问题
在使用carmen-rails和Rails4使用devise创建新用户时,country_code和states_code无法通过
允许使用country_code和state_code
以下是我的代码:
在设计注册中:
= 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}在用户/子区域中选择:
<% 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中
$('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中
get '/users/subregion_options' => 'users#subregion_options'在用户控制器中:
def subregion_options
render partial: 'subregion_select'
end在我的控制台上,所有的数据都被保存了,除了country_code: nil (即使我放了美国),当我选择一个国家时,states_code不会生成。
是因为我需要使用Formstatic吗?
感谢您的帮助:)
发布于 2014-04-24 05:25:17
看起来像是Devise卫生设施的问题。
#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)
}试一试吧!
干杯
https://stackoverflow.com/questions/20375927
复制相似问题