Rapid Rails setup - revisited

February 8th, 2007 -

I’ve taken some time to cleanup my set_rails bash script and have made many changes to it. One thing I’ve come to dislike about the script is passing the variables (app name, database, svn) when I am executing the script. I tend to forget which order I had them set in, thus making a script that was meant to quickly setup a Rails app without thinking, into having to think about it and, at times, open up the script to see what order the variables go in. Perhaps you’ve had the sample problem using the script?

Another aspect I dislike is having the svn check-in and check-out split into two scripts and that are ran at different times. Makes no sense, period. It all should be done within one full swoop.

So, I’ve got a new script for you – here’s the break down:

You type ./setup_rails.sh (name change too – makes sense) and hit return. The script will ask you some questions about your new Rails project, where your subversion repository is located, and where you want your checked-out version to be located. It’ll still ask what database you’ll be using and install some plugins for you. Those are the basics that were pretty much, but not quite, in the current version.

Now for the bigger changes that I’ve made. I wanted more flexibility, so I dumped paramter passing when calling the script (./setup_rails appname database svn) – confusing. I also don’t always check in my apps into subversion. The reason being, I like to create test applications and try out various things in Rails. I don’t need a version controlled test that won’t be used for anything other than a playground. Also, I don’t need the bloat of all those plugins that get installed in the current version. I don’t always use them all. When I first wrote the script, I was using them, so I naturally added them. I’ve slimmed that part down now. There are 5 standard plugins that may or may not be installed – you, the user can decide if you want them or not.

Run the script with this command ./setup_rails.sh

When the script runs, here is what goes on:

It asks:

  • would like to have your Application created on Edge Rails or not.
  • to name your application
  • what database you are going to use
  • would you like any of the following plugins installed:
    • Exception Notificaton
    • Continuous Builder
    • Simply Helpful
    • Routing Navigator
    • Annotated Models
  • and would you like to import this application into Subversion

If you say yes (y) to Subversion it will ask the following questions:

  • location of your subversion repository
  • account username
  • where would you like your checked-out version to be located (on your hard drive)

After those questions, it will do a recap, to make sure everything is in order. If so, you hit y (for yes to make the application) and the script then takes over doing all the hard work for you.

It will either create your application on Edge Rails or use whatever version of Rails (1.2.2 right?) you have installed on your machine. It will add a ChangeLog file, so you can keep changes and to-do’s in one place. It will create an application.rhtml file in your app/views/layouts folder and a couple of CSS files to use for screen and print.

It then installs your plugins, if you chose to have any installed. Then, if you wanted to import your application into Subversion, it does so. It also some some extra stuff:

  • removes edge Rails from the project and sets it to svn:externals
  • removes your log files from Subversion – svn:ignore
  • removes the tmp directory from Subversion – svn:ignore
  • moves your database.yml to database.sample
  • sets svn:ignore on database.yml

It does all those properly for you.

Then, it will edit the database.yml file, on your hard drive, and DRY it up. It will set your database to what you chose as well as sets the development, test, and production to the name of your application (appname_dev, appname_test, appname_production).

Phew. That is a lot. I believe this is the most comprehensive and flexible solution for creating a Rails application on a *nix environment (sorry windows people).

I’d love to hear your thoughts, suggestions and how you are using this script. Don’t be shy, come out of the shadows and at least just say hi. I’d like to get know all of you. Yes, you, you lurker!!

Grab the Script

 

Comments

Dr Nic

February 8th, 2007

Mate, go hardcore and write the script in Ruby as an executable in a gem.

gem install newgem
newgem setup_rails -b setup_rails

And then stick your Rubyified script in the setup_rails/bin/setup_rails file.

The release to the world of non-Unix people (read: moi), via:

rake release

(Once you’ve created a RubyForge project etc etc – see internals of the generated Rakefile for the new gem).

And then I don’t have to use cygwin and I can live happily in the world of Ruby :)

Robert

February 8th, 2007

lol! I’ve been meaning to make this a gem for a while now. I suppose I’ll have to get on this in the near future.

Ryan

February 8th, 2007

That’s a pretty sweet shell script – and it would make a nice shiny gem!

Robert

February 8th, 2007

Ok, ok, ok. I got the hint. Rails Gem coming up – give a week or so.

Peter

February 13th, 2007

mmm, something went wrong:

[code] Shall I create your application for you now Master? (y/n) y ./setup_rails.sh: line 273: syntax error near unexpected token `else’ ./setup_rails.sh: line 273: `else’ [/code]

Robert

February 13th, 2007

Oops, sorry about that Peter, typo on the close of the if..then statement.

Kenny

April 20th, 2007

Robert,

Did you turn it into a gem yet? If not… I will :-)

Robert

April 25th, 2007

I have it more than 50% of the way done and I have rubyforge project for it. When I get the time, I’ll finish it up. I’d like to keep working on it myself, it’s a fun project.

 

Commenting has been turned off.