Hello,
I’m a newbie to Rails but a relative old-timer on Ruby.
I’ve been going through the Onlamp Rails tutorial at
which is an excellent piece of work.
I have a few questions:
(1) On page 2 (and elsewhere), the following appears:
link_to %Q{#{recipe.title}}, ...
I don’t understand why the %Q{#{…}} construct has been used. Why not
just
link_to recipe.title
or
link_to recipe.title.to_s ?
(2) On page 3, the layout contains
<%= yield %>
but in my installation of Rails (Ubuntu rails package 1.1.2-1), the
template
had
<%= @content_for_layout %>
So I decided to stick with the latter format. However, I just want to
know,
is one preferred over the other? Is one deprecated?
(3) On page 4, in the recipe controller, the following lines are added:
@recipes = Recipe.find(:all,
:conditions => [“category_id = ?”,
params[:category_id]])
params[:category_id] = nil
But why set the parameter to nil after you’ve finished using it?
I also have a few comments.
(4) The database defines a column called ‘date’. However I’m using an
Oracle
database as the back-end, and it rejects this as a column name.
It might have been possible to quote the column name everywhere that
it’s
used, but I thought that was a bit of a risky strategy, so I just
changed
the column name to date_ent. This meant I had to make corresponding
changes
to the example code snippets.
So not a major problem, but it could make the example more portable if a
different name were used.
(5) On page 4, the narrative says:
“The error message is telling us we just tried to delete a record that
has
children. Rails stopped us from accidentally deleting a bunch of
recipes.”
To be accurate, the database has stopped us from accidentally deleting
a
bunch of recipes. The exception shows that Rails went ahead and tried to
delete the category, but the DB didn’t allow it.
(If you had configured the database with “ON DELETE CASCADE” then all of
those recipes would have been deleted as well…)
Anyway, those are just a couple of minor observations. This is a really
excellent tutorial and I’m sure will whet the appetite of many a
newcomer,
as it has done for me.
Regards,
Brian.