New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
country_select in nested model doesn't get filled when editing record #12
Comments
I think the problem you're having is that the partial is looking for an object called <div id="address_region_wrapper">
<% address ||= :address %>
<% country ||= params[:country] %>
<% country = Carmen::Country.coded(country) %>
<% if country.nil? %>
<em>Please select a Country above.</em>
<% elsif country.subregions? %>
<%= subregion_select(address, :region, country, {}, {:name => "customer[address_attributes][region]"}) %>
<% else %>
<%= text_field(address, :region, :name => "customer[address_attributes][region]") %>
<% end %>
</div> And then where you embed the partial: <%= render partial: 'region_select', locals: {country: address.object.country, address: address} %> There may be cleaner ways to handle passing the values in, but this should be a step in the right direction. |
Thanks for your anwer, Jim. Although it sounds reasonable, unfortunately that didn't change anything for me. I now solved it with The view:
And the partial:
The only problem remaining is that the |
I just pushed a fix for the lack of prompt support in |
Wow, this works like a charm. Thank you very much! |
Glad to hear it. |
@jim I also ran into the same issue and was able to solve it by modifying @jandillmann code. = f.simple_fields_for :addresses, defaults: {input_html: {class: "span3"}} do |address|
= address.hidden_field :content_type, :value => "Residence"
= address.input :address1
= address.input :address2
= address.input :city
= address.input :state, :wrapper_html => {:id => 'wrap-state'} do
= subregion_select_tag "person[addresses_attributes][0][state]", address.object.try(:state), "US", :prompt => "Select if applicable"
= address.input :zip_code
= address.input :country_code, :wrapper_html => {:id => 'wrap-country'} do
= country_select_tag "person[addresses_attributes][0][country_code]",
address.object.try(:country_code),
priority: %w(US),
prompt: 'Please select a country' |
I have a Customer model with an associated Address model. The Customer model accepts nested attributes for the Address. The Address has fields for country and region.
If I create a new Customer with it's associated Address, the Country and Region are saved to the database, but when I edit a record, the fields are not getting filled, i.e., the saved Country and Region are not selected.
Am I using this wrong or is it a bug, because when the country fields are in the main model and not in the associated model, everything works fine.
The view:
And the partial _region_select.html.erb:
The text was updated successfully, but these errors were encountered: