# Vim4Rails : project generator

**URL:** <https://www.ruby-forum.com/t/vim4rails-project-generator/93826>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/vim4rails-project-generator/93826 "2005-11-12T12:49:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/vim4rails-project-generator/93826/1 "2005-11-12T12:49:27Z")

</div>

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).

# 1 here’s the patch to rails app\_generator (eg C:\ruby\lib\ruby\gems\1.8\gems\rails-0.14.3\lib\rails\_generator\generators\applications\app\app\_generator) Index: app\_generator.rb

— app\_generator.rb (revision 2943)  
+++ app\_generator.rb (working copy)  
@@ -10,7 +10,8 @@  
def initialize(runtime\_args, runtime\_options = {})  
super  
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?  
end  
@@ -26,6 +27,10 @@
# Root
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",

```

“app/controllers/application.rb”  
@@ -34,7 +39,7 @@

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

```

:assigns =\> {

- 

```
   :app_name => 

```

File.basename(File.expand\_path(@destination\_root)),

- 

```
   :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  
2  
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” {  
}  
}

3  
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](http://www.vim.org/scripts/script.php?script_id=69), follow  
the included instructions to install the plugin on your system

4  
Create a new rails app with “rails #{your\_app}”

5  
Check that inside the root of your rails app there’s a file called  
vim4#{your\_app}

6  
open Vim

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

8  
enjoy!

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

Kev

---

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/vim4rails-project-generator/93826/2 "2005-11-12T12:49:27Z")

</div>

Hi,

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  
error:

“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…

Thanks…

* * *

Yahoo! FareChase: Search multiple travel sites in one click.  
[http://farechase.yahoo.com](http://farechase.yahoo.com)

---

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/vim4rails-project-generator/93826/3 "2005-11-12T12:49:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/vim4rails-project-generator/93826/4 "2005-11-12T12:49:28Z")

</div>

As I mentioned in my original posting:

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

Yes I did;)

— GeekEntrepreneu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> error:
> 
> execute this fine…  
> I am pretty much stuck here…  
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

Yahoo! Mail - PC Magazine Editors’ Choice 2005

> **[\[object](https://mail.yahoo.com/)**
>
> \[object

---

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [November 17, 2005, 7:46am UTC](https://www.ruby-forum.com/t/vim4rails-project-generator/93826/5 "2005-11-17T07:46:07Z")

</div>

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

Regards,  
Brett

---

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [December 14, 2005, 4:58pm UTC](https://www.ruby-forum.com/t/vim4rails-project-generator/93826/6 "2005-12-14T16:58:57Z")

</div>

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!
> 
> Regards,  
> Brett

Everyone,

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,  
geek001

---

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/vim4rails-project-generator/93826/7 "2005-11-12T12:49:29Z")

</div>

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:  
E:\ruby\lib\ruby\gems\1.8\gems\activerecord-1.13.0\lib\active\_record\connection\_adapters\mysql\_adapter.rb

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)  
begin  
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 =  
Mysql.const\_defined?(:VERSION)  
rescue LoadError =\> cannot\_require\_mysql  
# Only use the supplied backup Ruby/MySQL driver if no driver  
is already in place  
begin  
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 =  
true  
rescue LoadError  
raise cannot\_require\_mysql  
end  
end  
end

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…

regards  
Jan P.
