I have two models User and Advert. User has_many :adverts and Advert belongs_to :user. I use accepts_nested_attributes_for to update adverts attributes. This is how I do it:
class Users::RegistrationsController < Devise::RegistrationsController
@user = current_user
@user.update_attributes(adverts_attributes: [{id: ???, show_advert: false}])
end
For @user to be able to update advert he needs to have advert ID. If I just type ID advert e.g. 112 this works fine. I have also tried this way:
Advert.all.each do |advert|
@advert = advert.id
end
Worked only for oldest advert.
So how can I access advert ID?
Aucun commentaire:
Enregistrer un commentaire