Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Can I update all of my products to a specific user when seeding?
- admin = User.create(:name => "Admin", :password => "password")
- walmart = Store.create(:name => 'Walmart', :address => 'San Francisco, Palo Alto')
- walmartprices = walmart.products.create
- ([
- {:name => "Rice", :price => '5.93'},
- {:name => "Chicken", :price => "2.24"},
- {:name => "Milk", :price => '3.81'},
- {:name => 'Eggs', :price => '2.78'}
- ])
- walmartprices.update_attribute(:user => admin)
- undefined method `update_attribute' for #<Array:0x5342f70>
- Product
- belongs_to :user and :store
- Store
- has_many :products
- User
- has_many :products
- walmartprices.each{|record| record.update_attribute(user: admin) }
- Product.where( id: walmartprices.map(&:id) ).update_all( user: admin )
Add Comment
Please, Sign In to add comment