Update child attributes rails
<p>I have a customer model and book_room model</p>

<pre><code>class Customer &lt; ApplicationRecord
  has_many :book_rooms
  accepts_nested_attributes_for :book_rooms
end

class BookRoom &lt; ApplicationRecord
  belongs_to :customer
end 
</code></pre>

<p>in the book_room controller the create method is from its parent</p>

<pre><code>class BookRoomsController &lt; ApplicationController
 def create 
   @customer = Customer.find(params[:customer_id]) 
   @customer_room = @customer.book_rooms.create(book_rooms_params)
   flash[:notice] = "Customer has been added to room"
   redirect_to customer_path(@customer)
 end 
 def destroy 
   @customer = Customer.find(params[:customer_id]) 
   @customer_room = @customer.book_rooms.find(params[:id])
   @customer_room.destroy
   flash[:notice] = "Customer room has been deleted"
   redirect_to customer_path(@customer)
 end 
 def edit 
   @customer = Customer.find(params[:customer_id]) 
 end  
 def update 
   @customer = Customer.find(params[:customer_id]) 
   @customer.book_rooms.update(book_rooms_params)
   flash[:notice] = "Customer has checked out"
   redirect_to @customer
 end 
 private
 def book_rooms_params 
   params.require(:book_room).permit(:room, :first_name, :last_name, :phone_number, :checked_out)
 end
</code></pre>

<p>end</p>

<p>in the Customer show page </p>

<pre><code>&lt;%= form_for [@customer, @customer.book_rooms.build] do |f| %&gt;
&lt;% @room = Room.all %&gt;
&lt;%= f.label "Room: "%&gt;
&lt;%= f.select(:room, @room.collect { |a| [a.room_number, a.id] }) %&gt;
&lt;%= f.submit "Enter" %&gt;
&lt;div class="col-md-12"&gt;&lt;%= render @customer.book_rooms.order("created_at DESC") %&gt;&lt;/div&gt;
</code></pre>

<p>This works perfectly and all child objects get created. now when I try to edit the child attributes it doesn't update at all </p>

<p>heres the edit form in the book_room edit page/action</p>

<pre><code>&lt;%= form_for @customer do |f| %&gt;
&lt;%= f.fields_for :book_rooms, @customer.book_rooms do |f| %&gt;
  &lt;%= f.check_box :checked_out %&gt;
&lt;% end %&gt;
&lt;%= f.submit "Enter" %&gt;
</code></pre>



<p>is there something i am doing wrong? why doesn't it update? </p>

<p>Customers controller</p>

<pre><code>class CustomersController &lt; ApplicationController
before_action :set_customer, only: [:show, :edit, :update, :destroy]
# POST /customers.json
def create
@customer = Customer.new(customer_params)
respond_to do |format|
  if @customer.save
    format.html { redirect_to @customer, notice: 'Customer was successfully created.' }
    format.json { render :show, status: :created, location: @customer }
  else
    format.html { render :new }
    format.json { render json: @customer.errors, status: :unprocessable_entity }
  end
end
end
def update
respond_to do |format|
  if @customer.update(customer_params)
    format.html { redirect_to @customer, notice: 'Customer was successfully updated.' }
    format.json { render :show, status: :ok, location: @customer }
  else
    format.html { render :edit }
    format.json { render json: @customer.errors, status: :unprocessable_entity }
  end
  end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_customer
  @customer = Customer.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def customer_params
  params.require(:customer).permit(:first_name, :last_name, :phone_number, :sex, :book_rooms_attributes =&gt; [:checked_out])
end
</code></pre>