I started using Rails 2 last April but stopped this June because I thought learning it when Rails 3 was released would be more practical since a lot of it was completely refactored and restructured. I used to work with Ubuntu 10.04 (with SQLite3 as the default db) but now I'm using Windows 7 and MySQL 5. I already installed the gem adapter for MySQL, but to use it I still need to tweak database.yml. Thanks.
+2
A:
In terms of database configuration, nothing much has really changed between Rails 2 and 3 with the exception of how you load your MySQL driver. This used to be done in config/environment.rb
but is now done in Gemfile
:
gem 'mysql'
The default config/database.yml
file is set up with SQLite, but you can easily change this over to be MySQL. A generic version looks like:
defaults: &defaults
adapter: mysql
username: localdev
password: mylocaldevpasswordwhateveritis
host: localhost
development:
<<: *defaults
database: project_dev
test:
<<: *defaults
database: project_test
It's the adapter
declaration line that sets what driver to use.
tadman
2010-09-01 13:58:37
Is there a way to make mysql the default instead of sqlite?
Jason Noble
2010-09-01 14:25:31
For new projects? Not easily. This is a core feature of Rails. Typically people prepare a "skeleton" project for their new applications that's customized as required, with database drivers, plugins, gems all set up as you like them, then clone it for new projects. That way you can have any defaults you like, no matter how exotic.
tadman
2010-09-01 15:00:54
Thanks. So I cannot make it default for new projects.
arscariosus
2010-09-01 15:31:52
You can pass `--database=mysql` to the `rails new` command (or perhaps alias it in your shell - since on windows, maybe wrap the command in a batch of cmd script). Alternatively, you can create an application template: http://railscasts.com/episodes/148-app-templates-in-rails-2-3
Brian
2010-09-01 16:12:36
Nice trick with the command line option.
tadman
2010-09-01 18:15:56