require 'rubygems' require 'activerecord' ActiveRecord::Base.colorize_logging = false ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a')) # REMEMBER: look at the log file to see the queries ActiveRecord creates! ActiveRecord::Base.establish_connection( :host => 'db.students.mines.humanoriented.com', :username => 'YOUR_USERNAME', :password => 'YOUR_PASSWORD', :adapter => 'mysql', :database => 'YOUR_DB_NAME' ) # # Declare your classes here. Genre, Song, Album, Artist, etc. # class Genre < ActiveRecord::Base #set_table_name 'myGenreTable' #set_primary_key 'genreID' has_many :songs end class Song < ActiveRecord::Base belongs_to :genre has_and_belongs_to_many :nodes end # # Complete the project tasks. Some examples to get you started... # # genres = Genre.find(:all) # # s = Song.new # s.title = 'Tangled up in Blue' # a = Artist.new(:name => 'Bob Dylan') # s.artist = a # s.album = Album.new(:title => 'Highway 66 Revisited') # s.save # s.destroy rap = Genre.find_by_name('Rap') # rap is a Genre object p rap.songs.class # songs is a collection / array of Song objects # p is short for puts, think 'put string' or 'print' rap.songs.each do |song| # for every object in the songs array, take each p song.title # object and call it song. Now do stuff with song. p song.album.title end