RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: asboziev
Is there any way to update attributes for miltiple objects with nested form?
I used this code in controller:
@works = Work.find(params[:work_ids]) @works.reject! do |work| work.update_attributes!(params[:work]) end if @works.empty? redirect_to contracts_path else render :edit_multiple end
It is similar to example
But instead of updating the records, Ruby creates new ones and nullifies "work_id" in existing records.
mysql> SELECT * FROM work_comments; +----+---------+-------------+ | id | work_id | content | +----+---------+-------------+ | 1 | NULL | comment | | 2 | NULL | comment | | 3 | NULL | comment | | 4 | 1 | new comment | | 5 | 2 | new comment | | 6 | 3 | new comment | +----+---------+-------------+ 6 rows in set (0.00 sec)
What could cause this problem? Thank you!
Is there any way to update attributes for miltiple objects with nested form?
I used this code in controller:
It is similar to example
But instead of updating the records, Ruby creates new ones and nullifies "work_id" in existing records.
What could cause this problem? Thank you!