Closed lawrobi closed 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?
haha yes I posted there too.
Of course, I generated them too.
Ok it works :) I just needed to put default => "", and null => false
Thanks
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 :)