carmen-ruby / carmen-rails

NOT ACTIVELY MAINTAINED Rails adapter for Carmen (provides country_select and subregion_select)
MIT License
215 stars 159 forks source link

Carmen with devise(Ruby on rails) country_code: nil #37

Closed lawrobi closed 10 years ago

lawrobi commented 10 years ago

Hey Everyone, I'm new and I have a basic question

When I create a new user with devise using carmen-rails with Rails 4, country_code and states_code don't pass

Both country_code and state_code are permitted

Here are my codes:

in Devise registration:

= 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}

in users/ _subregion_select:

<% 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 %>

in 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)

in routes.rb

get '/users/subregion_options' => 'users#subregion_options'

in users controllers:

def subregion_options render partial: 'subregion_select' end

On my console, all the data are saved except for country_code: nil (even though I put United States) and the states_code is not generated when I select a country.

Is that because I should need to use Formstatic?

Thank you for your help :)

frandroid commented 10 years ago

If you have a basic question, maybe you should ask on StackOverflow instead?

It likely has nothing to do with needing Formtastic. Have you generated the columns needed in your user table?

lawrobi commented 10 years ago

haha yes I posted there too.

Of course, I generated them too.

lawrobi commented 10 years ago

Ok it works :) I just needed to put default => "", and null => false

Thanks