K
K
kramidev2015-01-28 13:16:36
Ruby on Rails
kramidev, 2015-01-28 13:16:36

rails. relation has_many. How to update correctly?

Hello gurus inhabitants. There are 2 models
personal -> has_many: personal_pictures
picture -> belongs_to: personal
When uploading one photo, I do this:

@personal = Personal.new(personals_params)
@personal.personal_pictures.build(picture: params[:pictures]['picture'], personal_id: personal.id)
@personal.save

The question is how to do an update? I don’t want to search for a photo by ID and update it.
??????????????????????
@personal = Personal.find(params[:id])
@personal.personal_pictures.update(picture: params[:pictures]['picture'], personal_id: @personal.id) 
@personal.update(personals_params)

??????????????????????

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-01-28
@viktorvsk

api.rubyonrails.org/classes/ActiveRecord/NestedAtt...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question