Skip to content

Instantly share code, notes, and snippets.

@Sunnyztj
Last active December 31, 2015 21:49
Show Gist options
  • Save Sunnyztj/8049825 to your computer and use it in GitHub Desktop.
Save Sunnyztj/8049825 to your computer and use it in GitHub Desktop.
update database in rails
tootz git:(develop) rails c
[1] pry(main)> User.where("email like '%webztj%'")
[2] pry(main)> u = User.find 1
[3] pry(main)> Ticket.create user_id: 1
[4] pry(main)> Message.create user_id: 2, subject: 'hello wolrd', body: 'good day'
reload!
Ticket.all.each{|t| t.assign_images }
u = User.find 1
u.tickets
u.tickets.update_all(draw_id: 2)
Ticket.all.each{|t| t.assign_images }
u.tickets.each{|t| t.assign_images}
u.tickets.reload
u.tickets.each{|t| t.assign_images}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment