Rails 3,how to update a habtm table in the rails console?
-
15-04-2021 - |
Question
I have Awards - Awards_Categories - Categories in a HABTM association.
I updated my routes so that
resources :categories do
resources :awards
end
I have two awards that didn't have a category so now accessing them from the admin is not working.
How would mess with this in the console. Its pretty straight forward, I need award(15) and award(16) to have category 4...
ideas?
Solution
category = Category.find(4)
[15, 16].each{|k| Award.find(k).categories << category }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow