Guest User

Untitled

a guest
Sep 19th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. thufir@dur:~/ruby/dwemthys$
  2. thufir@dur:~/ruby/dwemthys$ ruby connect.rb
  3. connecting...
  4. connected?
  5. class Creature
  6. life life
  7. strength str
  8. charisma char
  9. weapon weapon
  10. #<Creature:0x8bd5648>
  11.  
  12. [1]+ Stopped ruby connect.rb
  13. thufir@dur:~/ruby/dwemthys$
  14. [1]+ Done ruby connect.rb
  15. thufir@dur:~/ruby/dwemthys$
  16. thufir@dur:~/ruby/dwemthys$ cat connect.rb
  17. require 'fileutils'
  18. require 'active_record'
  19. require_relative 'Creature'
  20. require_relative 'Dragon'
  21.  
  22. puts "connecting..."
  23.  
  24. ActiveRecord::Base.establish_connection(
  25. :adapter => "mysql",
  26. :host => "localhost",
  27. :username => "java",
  28. :password => "password",
  29. :database => "nntp"
  30. )
  31.  
  32. puts "connected?"
  33.  
  34. c = Creature.new
  35.  
  36. c.life = "life"
  37. c.strength = "str"
  38. c.charisma = "char"
  39. c.weapon = "weapon"
  40.  
  41. puts c
  42.  
  43. c.save
  44. thufir@dur:~/ruby/dwemthys$
  45. thufir@dur:~/ruby/dwemthys$ cat Creature.rb
  46. require 'active_record'
  47.  
  48. class Creature < ActiveRecord::Base
  49.  
  50. attr_accessor :life, :strength, :charisma, :weapon
  51.  
  52. def to_s ()
  53. print "class\t\t"
  54. print self.class
  55.  
  56. print "\nlife\t\t"
  57. print @life
  58.  
  59. print "\nstrength\t"
  60. print @strength
  61.  
  62. print "\ncharisma\t"
  63. print @charisma
  64.  
  65. print "\nweapon\t\t"
  66. print @weapon
  67. print "\n"
  68. end
  69.  
  70.  
  71. end
  72. thufir@dur:~/ruby/dwemthys$
  73. thufir@dur:~/ruby/dwemthys$ mysql -u java -p
  74. Enter password:
  75. Welcome to the MySQL monitor. Commands end with ; or \g.
  76. Your MySQL connection id is 238
  77. Server version: 5.1.58-1ubuntu1 (Ubuntu)
  78.  
  79. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  80. This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  81. and you are welcome to modify and redistribute it under the GPL v2 license
  82.  
  83. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  84.  
  85. mysql> use nntp;
  86. Reading table information for completion of table and column names
  87. You can turn off this feature to get a quicker startup with -A
  88.  
  89. Database changed
  90. mysql> select * from creatures;
  91. +----+------+----------+----------+--------+
  92. | id | life | strength | charisma | weapon |
  93. +----+------+----------+----------+--------+
  94. | 1 | NULL | NULL | NULL | NULL |
  95. | 2 | NULL | NULL | NULL | NULL |
  96. | 3 | NULL | NULL | NULL | NULL |
  97. | 4 | NULL | NULL | NULL | NULL |
  98. | 5 | NULL | NULL | NULL | NULL |
  99. | 6 | NULL | NULL | NULL | NULL |
  100. | 7 | NULL | NULL | NULL | NULL |
  101. | 8 | NULL | NULL | NULL | NULL |
  102. | 9 | NULL | NULL | NULL | NULL |
  103. +----+------+----------+----------+--------+
  104. 9 rows in set (0.00 sec)
  105.  
  106. mysql> quit;
  107. Bye
  108. thufir@dur:~/ruby/dwemthys$
Add Comment
Please, Sign In to add comment