Setting up a new Rails project in Subversion
Create a folder to put all the junk you need to set things up.
mkdir svn_setup
cd svn_setup
Create the standard SVN folder structure.
mkdir tags
mkdir branches
Create a new Rails project and rename it to be the trunk folder.
rails project_name
mv project_name trunk
The reason to do this is so your database.yml file (among others) will have the right project name instead of trunk_development, etc.
A little housekeeping before putting the files into the repository.
cd trunk
rm -r tmp/*
rm -r log/*
mv config/database.yml config/database_example.yml
Put the files into the repository.
cd ..
svn import . svn_project_url -m "initial import of blank Rails project" --username whathaveyou
Checkout the files and tell Subversion to ignore some files.
cd ..
svn co svn_project_url/trunk project_name
cd project_name
cp config/database_example.yml config/database.yml
svn propset svn:ignore database.yml config/
svn propset svn:ignore "*" log/
svn propset svn:ignore "*" tmp/
If you want, setup Rails with svn:externals to that it will be ready for you to lock it into a particular version for stability.
svn propedit svn:externals vendor/
In the file that pops up, enter this (or enter whatever version you want to use–such as http://dev.rubyonrails.org/svn/rails/trunk/ for edge):
rails http://dev.rubyonrails.org/svn/rails/tags/rel_1-2-3/
Save then close the file.
Check the changes back into the repository.
svn ci -m "Ignore database.yml, log/, and temp/. Set up Rails with svn:extnrnals"
Then update your checkout to get the Rails external to load.
svn up
Other things:
When you’re done with everything you can delete the svn_setup folder. I think I’m going to keep mine around for a slight head start on more projects.
Don’t forget to use the -c option when you run script/generate to automatically add the files to Subversion.
script/generate scaffold_resource angryfarmer name:string bales_of_hay:integer -c
When installing plugins, use the -x option to make it an svn:external
script/plugin install -x robot_cow
Comments
If your svn:externals file says this:
Then, you’re using edge rails, which will change often. Every time the Rails trunk gets a new changeset, your “svn update” command is going to download it, and you have no control over it.
If your want to work with today’s edge Rails (but not necessarily tomorrow’s edge Rails), the best thing to do is lock your project to a specific revision of the trunk, you can specify it like this:
Then, you can change the revision number whenever you feel that it is safe to do so.
I personally prefer to use the official releases for production apps The official stable releases are found in the tags directory like:
Finally, there is one more option. That is to lock your project to a specific major release, but get updates whenever there is a minor release. There are pros and cons to this method. On the plus side, you always have the latest bug fixes for your chosen release; on the down side, you don’t ever know when an “svn update” is going to pull a new release of Rails into your project. I think it’s best to use the previous method, and just edit your svn:externals whenever there is a minor release. They keep the latest stable release in a branch. Reference it like this:
Ah. That makes lots of sense. But what would you do if you already ran a bunch of
(formerly scaffold_resource) and it created .erb instead of .rhtml files?
I haven’t used edge in a while. Didn’t know they were doing .erb instead of .rhtml. I guess you have two options:
I think I will choose option 2 for now.
For the record, I’ve deleted my repository and started over using Rails 1.2.3 as you recommended. Luckily, I hadn’t really started any work on it yet.
What do you think about that?