As a trivial example, let's say I have:
class Garage
has_many :things
accepts_nested_attributes_for :things
end
class Thing
# has a name attribute
belongs_to :garage
belongs_to :user
end
class User
...
end
I have a GaragesController that accepts a POST for a new garage and all the things in it.
def create
@garage = Garage.create(safe_garage_params)
end
def safe_garage_params
params.require(:garage).permit(...)
end
I have to set the user for each/all of the Things that are created. Obviously I can crawl the safe_garage_params hash and set user for each of the Thing hashes in the things_attributes array. But that seems pretty klutzy. Is there a better/cleaner way?
And, of course, in my actual program the child array can go a few tiers deep - which makes the crawling uglier.
Maybe like this:
With
CurrentAttributes:https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html