Skip to content

Instantly share code, notes, and snippets.

@inutano
Created January 27, 2012 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inutano/1687146 to your computer and use it in GitHub Desktop.
Save inutano/1687146 to your computer and use it in GitHub Desktop.
てめー ブッ殺す! 『アクティブ・レコード』ッ!
require "active_record"
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => './test.sqlite3'
)
class UsersInit < ActiveRecord::Migration
def self.up
create_table( :users ) do |t|
t.string :user_name, :null => false
t.string :twitter_id, :limit => 25, :null => false
t.timestamps
end
end
def self.down
drop_table :users
end
end
UsersInit.migrate(:up) if File.exist?("./test.sqlite3")
class User < ActiveRecord::Base
def to_s
"#{user_name}(#{twitter_id}), up:#{updated_at}"
end
end
User.create( :user_name => "inutano", :twitter_id => "iNut" )
User.create( :user_name => "benjo", :twitter_id => "y_benjo")
User.create( :user_name => "yag", :twitter_id => "yag_ays")
User.find( :all ).each do |user|
puts user.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment