Guest User

Untitled

a guest
Mar 8th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. # connect to the database
  2. ActiveRecord::Base.establish_connection(
  3. :adapter => "mysql", :database => "mydb",
  4. :host => "localhost", :username => "mydb_user",
  5. :password => "foo" )
  6.  
  7. # create a model object
  8. class Contact < ActiveRecord::Base
  9. end
  10.  
  11. # persist!
  12. Contact.create "name" => "Charles Nutter", "title" => "JRuby Developer"
  13. Contact.create "name" => "Thomas Enebo", "title" => "JRuby Developer"
  14.  
  15. # query
  16. Contact.find(:all).each {|c| puts c.name}
  17. nutter = Contact.find_by_name("Charles Nutter")
  18.  
  19. # update
  20. nutter.title = "Dark Overlord of the Universe"
  21. nutter.save
Add Comment
Please, Sign In to add comment