Vim4Rails : project generator

I was thinking about this last night after spending some time messing
with a project plugin for Vim. This morning I hacked up a quick patch
for the rails app_generator to automatically setup a vim project file.
It works, but I knew it wouldn’t be a particularly good fit for the core
of rails - still nothing ventured etc. Anyway it was suggested that
perhaps peopel on the rails list might be intrigued…

Anyway if you’re a vim user, this might make starting your rails
projects easier (note I’m a long time vi user, but in no way would I
consider myself advanced, so any suggestions would be helpful).

here’s the patch to rails app_generator (eg
Index: app_generator.rb

— app_generator.rb (revision 2943)
+++ app_generator.rb (working copy)
@@ -10,7 +10,8 @@
def initialize(runtime_args, runtime_options = {})
usage if args.empty?

  • @destination_root = args.shift
  • @destination_root = args.shift
  • @app_name = File.basename(File.expand_path(@destination_root))
    @socket = MYSQL_SOCKET_LOCATIONS.find { |f| File.exists?(f) }
    @socket = ‘/path/to/your/mysql.sock’ if @socket.blank?
    @@ -26,6 +27,10 @@


    m.file “fresh_rakefile”, “Rakefile”
    m.file “README”, “README”
  •  m.template "vim4rails", "vim4#{@app_name}", :assigns => {
  •    :app_name => @app_name,
  •    :location => File.expand_path(@app_name)
  •  }
     # Application
     m.template "helpers/application.rb",

@@ -34,7 +39,7 @@

   # database.yml and .htaccess
   m.template "configs/database.yml", "config/database.yml",

:assigns => {

  •    :app_name => 


  •    :app_name => @app_name,
       :socket => @socket
     m.template "configs/routes.rb",     "config/routes.rb"

after patching app_generator you need to add this file (contents below)
to eg if your rails gem is installed like mine (on
windows) c:\ruby\lib\ruby\gems\1.8\gems\rails-0.14.3
Save this as “vim4rails”

<%= app_name %>=<%= location %> CD=. {
View=app/views CD=. {
Controllers=app/controllers CD=. filter=“.rb" {
Models=app/models CD=. filter="
.rb” {
YAML=config CD=. filter=“.yml" {
DDL=db CD=. filter="
.ddl .sql" {
Tests=test CD=. {
Fixtures=fixtures CD=. filter="
.yml” {
Functional=functional CD=. filter=“.rb" {
Unit=unit CD=. filter="
.rb” {
Stylesheet=public/stylesheets CD=. filter=“*.css” {

Now you need to download and set up the project plugin I used - download
from here : project.tar.gz - Organize/Navigate projects of files (like IDE/buffer explorer) : vim online, follow
the included instructions to install the plugin on your system

Create a new rails app with “rails #{your_app}”

Check that inside the root of your rails app there’s a file called

open Vim

7 (and finally)
Load the project file for your rails app…
go into command mode (ESC)
type :Project /vim4#{your_app}


I’m quite happy with it, I’d like to turn it into a real generator, any
other suggestions welcome.



I tried following the instructions on Agile Web
Development w/ Rails book to install RoR on my machine
(windows XP). And, afterwards tried to create a
scaffold using:

“ruby.exe script/generate scaffold Product Admin” as
mentioned in the book. And, I got the following error:

“Before updating scaffolding from new DB schema, try
creating a table for your model (Product)”

As I mentioned my development machine is Windows XP
(installed ruby 1.8.2, rails 0.14.3), and am using
mysql 4.1 on a linux machine. Connect string in
database.yml is correct (verified everything over and
over again).

Also, when I look at the development log, I see an

“Lost connection to MySQL server during query: SHOW
FIELDS FROM products”

I tried executing this sql, and it works fine too,
which means products table is there and can be found
without problems… Also, I can connect to the same
database from java using jdbc, and I can connect and
execute this fine…

Am I missing something here? Have been trying to get
this working for the last 2 days, and it keeps giving
this error. I tried downgrading to rails 0.13.1. But,
getting the same error.

Can anyone pleasee help? This is driving me crazy and
I am pretty much stuck here…


Yahoo! FareChase: Search multiple travel sites in one click.

Have you updated the database.yml to point to the correct db?

As I mentioned in my original posting:

“Connect string in database.yml is correct (verified
everything over and over again).”

Yes I did;)

— GeekEntrepreneu [email protected]


execute this fine…
I am pretty much stuck here…
Rails mailing list
[email protected]

Rails mailing list
[email protected]

Yahoo! Mail - PC Magazine Editors’ Choice 2005

Thank you so much for this workaround! I have been fighting with trying
to get this working and was about to give up. Thanks!


Brett wrote:

Thank you so much for this workaround! I have been fighting with trying
to get this working and was about to give up. Thanks!



I am having the same error using XP. I tried to use the above
workaround, but that line is not in my mysql_adapter.rb file.

Any other ideas. I am running version 1.82 with mysql 4.1

Thanks in advance,

Hi, Cabbar,

please try to comment out the row require
‘active_record/vendor/mysql411’ in mysql_adapter which is in my
installation is located at:

The resulting file would after that begin with:

module ActiveRecord
class Base
# Establishes a connection to the database that’s used by all Active
Record objects.
def self.mysql_connection(config) # :nodoc:
# Only include the MySQL driver if one hasn’t already been loaded
unless self.class.const_defined?(:Mysql)
require_library_or_gem ‘mysql’
# The C version of mysql returns null fields in each_hash if
Mysql::VERSION is defined
ConnectionAdapters::MysqlAdapter.null_values_in_each_hash =
rescue LoadError => cannot_require_mysql
# Only use the supplied backup Ruby/MySQL driver if no driver
is already in place
require ‘active_record/vendor/mysql’
# require ‘active_record/vendor/mysql411’
##################### this is the row ########################
# The ruby version of mysql returns null fields in each_hash
ConnectionAdapters::MysqlAdapter.null_values_in_each_hash =
rescue LoadError
raise cannot_require_mysql

This helped me (and others whom advice I’ve followed) -
connection-bindings to mysql, native ones more than the default
ruby-bindings seem to be a bit of a problem at the moment…

Jan P.