Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'active_record'
- require 'tiny_tds'
- require 'activerecord-sqlserver-adapter'
- ActiveRecord::Base.establish_connection(
- :adapter=> "sqlserver",
- :host => "localhost",
- :username => "sa",
- :password => "your_password",
- :database => "SampleDB"
- )
- ActiveRecord::Schema.define do
- create_table :articles, force: true do |t|
- t.string :title
- t.string :author
- end
- end
- class Article < ActiveRecord::Base
- def to_s
- "Title: #{title}, Author:#{author}"
- end
- end
- #Creating a new article
- Article.create(title:'ORM', author:'Andrea')
- Article.create(title:'test', author:'fake')
- #Fetching a first article
- article = Article.first
- puts article.to_s
- #Fetching article by author
- fake_article = Article.find_by(author: 'fake')
- puts fake_article.to_s
- #Destroy an article
- Article.find_by(author: 'fake').destroy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement