just in ram

A list of stuff I should remember but never do

Archive for the ‘Ruby on Rails’ Category

Connecting Ruby on Rails to Microsoft SQL Server

with 8 comments

NOTE: These instructions are now seriously out of date. You may want to check out my always up to date *cheap* ebook instead. Connecting Ruby on Rails to Microsoft SQL Server eBook

It appears rails does not connect to MS SQL Server right out of the box. You need to do the following to get the connection to work:

Get the latest source distribution of Ruby-DBI and copy the file:

bdi-0.1.0/lib/dbd/ADO.rb

to:

c:/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb

NOTE: The ADO directory does not exist on a standard install, you will need to create it.

Then simply set up your railsapp/config/database.yml

Here’s an example for reference:

development:
  adapter: sqlserver
  database: database_name
  host: server_name
  username: user_name
  password: your_pw_here

Written by Justin Ramel

April 7th, 2006 at 8:39 pm

Posted in Ruby on Rails

Migrations 'Zombie State' and MS SQL

with one comment

Getting ‘Zombie State’ errors with migrations and MS SQL Server? Add the following to your config/enviroment.rb:

ActiveRecord::Base.connection.instance_variable_get("@connection")["AutoCommit"] = false

Written by Justin Ramel

April 4th, 2006 at 1:28 pm

Posted in Ruby on Rails

Pluralize table names – no thanks!

with 11 comments

Sorry I just can’t live with plural table names, I just can’t get my head around it! Luckily it is easily turned off. In RadRails there is a simple tick box when creating the project which simply adds the following line to the end of your applications config/environment.rb file:

# Include your application configuration below
ActiveRecord::Base.pluralize_table_names = false

I may live to regret not embracing plural table names but I doubt it!

Written by Justin Ramel

April 4th, 2006 at 1:05 pm

Posted in Ruby on Rails

Setting up Ruby on Rails

with 5 comments

I’m going to give Ruby on Rails (RoR) a try on my Windows XP machine. Here’s how I’ve set it up…

  1. Install Ruby
    Using the Ruby One Click Installer Ruby One Click Installer (v184-16 release candidate 1)
  2. Setup proxy
    set HTTP_PROXY=http://wwwcache:8080
  3. GEM install Ruby on Rails
    gem install rails --include-dependencies
  4. Install RadRails
    I also downloaded and installed the latest RadRails (v0.6.1)
  5. Database
    I’m going to try rails with our dev MS-SQL server so no database to install. No doubt lots of configuring to do though!

NOTE:

There appears to be a problem with the WEBrick web server in this setup. I couldn’t find the answer on google but I did find a work around. If you run the WEBrick server using the standard ruby script\server you will get the following error:

ruby script\server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-04-04 13:20:35] INFO  WEBrick 1.3.1
[2006-04-04 13:20:35] INFO  ruby 1.8.4 (2005-12-24) [i386-mswin32]
[2006-04-04 13:20:35] WARN  TCPServer Error: Bad file descriptor - bind(2)
c:/ruby/lib/ruby/1.8/webrick/utils.rb:73:in `initialize': Bad file descriptor - bind(2) (Errno::EBADF)
        from c:/ruby/lib/ruby/1.8/webrick/utils.rb:73:in `create_listeners'
        from c:/ruby/lib/ruby/1.8/webrick/utils.rb:70:in `create_listeners'
        from c:/ruby/lib/ruby/1.8/webrick/server.rb:75:in `listen'
        from c:/ruby/lib/ruby/1.8/webrick/server.rb:63:in `initialize'
        from c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:24:in `initialize'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:59:in `dispatch'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/servers/webrick.rb:59
        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
        from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in `require'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/server.rb:30
        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
        from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in `require'
        from script/server:3

There appears to be some problem binding to the port 3000, netstat shows nothing running on port 3000 so I’ve no idea what is causing it. Any hoose a work around is simply to run on another port:

ruby script\server --port=8000

If I do find out what is causing the problem I’ll update this post.

Written by Justin Ramel

April 4th, 2006 at 10:26 am

Posted in Ruby on Rails