A user has many user_levels and a user_level belongs to a user. We are
having difficulty updating the user_level. Here is the code for
user_level update:
<%= simple_form_for @user do |f| %>
<% @user.user_levels.each do |level| %>
<%= f.fields_for :user_levels, level, :index => level do |
builder| %>
<%= render :partial => ‘user_levels’, :locals => {:f =>
builder, :i_id => level.position} %>
<% end %>
<% end %>
<% end %>
The code above will display the current user_level with selected set
to the current position. But the update was not saved for user_level.
Here is the user_levels partial
<div class="fields">
<%= f.input :position, :collection => return_position, :prompt
=> “Choose position”,
:label => false, :include_blank =>
true, :selected => i_id %>
<%= link_to_remove_fields “remove”, f %>
Here is the string posted to the server for params[:user]. There are
currently two positions for the user and one gets deleted as update:
{"name"=>"test eng", "login"=>"tester12", "password"=>"password",
“password_confirmation”=>“password”, “user_type”=>“employee”,
“user_levels_attributes”=>{“0”=>{“id”=>“5”},
“1”=>{“position”=>“elec_eng”, “_destroy”=>“false”, “id”=>“6”}}}
The app has no problem creating a new user with multiple user_levels.
Any solution for child update? Thanks so much