在windows下快速使用rails3和SqlServer2008

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

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

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,这环境每回安装都会有奇怪的问题。

```bash DOS rails new test_sqld



```ruby Gemfile
#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 ```yml database.yml development:
adapter: sqlserver #host: localhost database: myapp_development username: sa password: '11111111'


然后
```bash DOS
bundle install

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

```bash Dos rails g model User


```ruby db\migrate\xxxxxxxxxxxxxx_create_users.rb
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

```bash Dos rake db:migrate rails c

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





参考:

[https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki)

[http://railsinstaller.org](http://railsinstaller.org)

Comments