Ruby on Rails Changes and Troubleshooting
Several key features of Rails have changed since I recorded Ruby on Rails: Essential Training and Ruby on Rails: Beyond the Basics. This list should help anyone who has run into a problem still learn Ruby on Rails while we work to update the training videos.
The installation instructions have changed. In particular, if you are on a Mac running MacOS 10.5 (Leopard), Ruby and Ruby on Rails are already installed. You can always get the latest instructions at http://www.rubyonrails.org/download
Starting with Rails 2.0.2, SQLite became the default database. Previously, and in my training videos, it was MySQL. The only difference is the content of /your_app/config/database.yml. To use MySQL instead of SQLite, you can either change database.yml to match mine or you can specify the database when you first generate your Rails project using: rails -d mysql your_app. (If you already created your Rails project, you can create a new one and just steal its database.yml file.)
Dynamic scaffolding was removed starting in Rails 2.0.2. Watch the movie, “Scaffold: Magic CRUD”, so you get the general idea, but you don’t need to follow along. Even though it’s gone, I think it is still instructive to see the basic elements of CRUD (Create, Read, Update, and Delete) in action. It also showcases off Rails’ sensible default configurations. I think I even say in the video “Scaffold is a neat trick but it is not something you will need to use.” That was so true that they decided to remove it!
In all versions of Rails, you can generate files that provide the same behavior as dynamic scaffolding. It is a useful way to add the basic CRUD actions to your project without having to type it out. But in Rails 2.0, scaffold generation changed so that the scaffold code you get is in an advanced RESTful style. This is unfortunate for beginners because, in my opinion, the old style is a million times easier for beginners to follow. You can either copy what you see in the videos in place of the generated scaffold code, or you can install my CRUD scaffold plugin which will let you generate scaffolds in the old style (plus a few minor improvements).
Rails 2.0 changed the way forms are coded.
<%= start_form(...) %>
<%= end_form_tag %>
It is now:
<% form_tag(...) do -%>
<% end -%>
Notice that the start and end are different, the equal-signs are gone from the tags, and the word do has been added. (It is now a Ruby code block.) If you have a newer version or Rails, you will want to change all of your forms to match this new format.
View Template File Extensions
Rails 2.0 also changed the file extensions for view templates. Instead of being “.rhtml”, they are now “.html.erb”. The new naming indicates the desired output format followed by the templating engine to use for processing. Rails 2.0 still allows “.rhtml” without any problem, so you don’t need to make any change yet, but Rails 3.0 will likely only support the new format.
Pagination has been removed from the core of Rails 2.0 but is still available as a plug-in. You can either ignore pagination while learning the basics, or you can read more about it (here and here) and install one of the pagination plugins.