在windows下快速使用rails3和SqlServer2008

win下快速安装http://railsinstaller.org/

含包了以下的组件,也支持连结sql server的gem

1
2
3
4
5
6
7
8
Ruby 1.9.3-p125
Rails 3.2
Bundler 1.0.18
Git 1.7.6
Sqlite 3.7.3
TinyTDS 0.4.5
SQL Server Support 3.3.3
DevKit

下载railsinstaller-2.1.0,下一步..下一步..完成。 ruby on rails的环境就优雅的搞定。高兴的是他支持SqlServer,这环境每回安装都会有奇怪的问题。

DOS
1
rails new test_sqld
Gemfile
1
2
3
4
5
6
7
8
9
#source 'https://rubygems.org' 
#上一行注掉改为
source 'http://ruby.taobao.org'


#gem 'sqlite3'
#把 sqlite3改为以下,为了支持SqlServer
gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter', '3.2.1'

连结数据库配置,高级配置查看Using-TinyTDS

database.yml
1
2
3
4
5
6
development:   
  adapter: sqlserver
  #host: localhost
  database: myapp_development
  username: sa
  password: '11111111'

然后

DOS
1
bundle install

我们建一个model连下SqlServer试一试

Dos
1
rails g model User
db\migrate\xxxxxxxxxxxxxx_create_users.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users, :force => true do |t|
    t.column :ten_code,       :char,      :limit => 10
    t.column :ten_code_utf8,  :nchar,     :limit => 10
    t.column :title_utf8,     :nvarchar
    t.column :body,           :varchar_max    # Creates varchar(max)
    t.column :body_utf8,      :ntext
    t.column :body2_utf8,     :nvarchar_max   # Creates nvarchar(max)
      t.timestamps
    end
  end
end
Dos
1
2
3
4
5
rake db:migrate
rails c

User.create(:ten_code=>'test')
User.first

参考:

https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki

http://railsinstaller.org

原文地址:http://dlj.bz/MTYjhT

Comments