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 <path to rails gem> 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 : 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 <path to your rails app>/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
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
Have you updated the database.yml to point to the correct db? -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Cabbar Duzayak Sent: Wednesday, November 09, 2005 11:06 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] Rails Installation on Windows 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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
As I mentioned in my original posting: "Connect string in database.yml is correct (verified everything over and over again)." Yes I did;) --- GeekEntrepreneu <geekentrepreneur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Have you updated the database.yml to point to the > correct db? > > -----Original Message----- > From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On > Behalf Of Cabbar Duzayak > Sent: Wednesday, November 09, 2005 11:06 AM > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails] Rails Installation on Windows > > 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 > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________ Yahoo! Mail - PC Magazine Editors'' Choice 2005 http://mail.yahoo.com
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 Prill
Cabbar Duzayak wrote:
>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
>_______________________________________________
>Rails mailing list
>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
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 -- Posted via http://www.ruby-forum.com/.
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, > BrettEveryone, 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 -- Posted via http://www.ruby-forum.com/.