| Article: |
Rolling with Ruby on Rails Revisited | |
| Subject: | is the code complete ? | |
| Date: | 2006-12-17 15:30:55 | |
| From: | will_macdonald | |
|
I just followed all the example using Locomotive.
|
||
Showing messages 1 through 10 of 10.
-
is the code complete ?
2006-12-20 13:49:02 Bill Walton | [View]
-
is the code complete ?
2007-01-06 23:59:31 nelsmartens [View]
After too many discussions of metaprogramming, migration and 'what happens under the hood', I wondered if I would find a document that produced a functioning demo.
Your article made my week. Errors and all :)
Thank you,
Nels
-
is the code complete ?
2006-12-20 16:39:30 sbaptista [View]
First of all, thanks for the quick response.
>It will fail for exactly the reason you're seeing...You're going to have to wait for the second installment.
OK, now I know I didn't miss something.
> If you just can't wait to enter a recipe, just take the foreign key constraint (and the field) out of the script.
Reminds me that I made a mental note to look into how Rails handles/supports database modifications (or maybe that would be a migration issue(?).
Any chance the next installment might speak to that?
-
is the code complete ?
2006-12-20 12:10:44 sbaptista [View]
> When trying to enter a recipe it fails because foreign key is absent. It is not an option on the [web] page.
I've got the same problem. If you notice, the article screenshot for a new recipe ("Figure 11 new recipe entry page") on page 2 also does not offer a way to select a category.
Presumably, the code generator is supposed to detect the contraint and display something in the UI??
Some notes:
MySQL version: 5.0.27.
I used the following script to generate the database:
drop table if exists recipes;
drop table if exists categories;
create table categories (
id int not null auto_increment,
name varchar(100) not null default '',
primary key(id)
) engine=InnoDB;
create table recipes (
id int not null auto_increment,
category_id int not null,
title varchar(100) not null default '',
description varchar(255) null,
date date null,
instructions text null,
constraint fk_recipes_categories foreign key (category_id) references
categories(id),
primary key(id)
) engine=InnoDB;
-
is the code complete ?
2007-10-18 11:17:56 miwi1142 [View]
When I go to http://localhost:3000/recipe
and click on create, and fill out the form,
the submit does not go through because category_id is not being preset. In fact category does not show up in the recipe screen, just like in your screenshot. How can I fix that?
Mysql::Error: #23000Column 'category_id' cannot be null: INSERT INTO recipes (`title`, `date`, `category_id`, `description`, `instructions`) VALUES('afdsfa', '2007-10-18', NULL, 'dfsafas', 'dfsafsafdsa')
-
is the code complete ?
2007-10-21 12:27:08 Bill Walton | [View]
Hi,
You're definitely not the first to ask the question ;-) The answer can be found in the second paragraph of my response just above, dated 2006-12-20.
Best regards,
Bill
-
is the code complete ?
2006-12-18 06:26:00 Bill Walton | [View]
Hi Will,
Much of Rails' magic requires transaction support which, in MySQL, is only available via the InnoDB engine. From the MySQL developer documentation (http://dev.mysql.com/doc/refman/4.1/en/create-table.html ) "In MySQL 3.23.44 or later, InnoDB tables support checking of foreign key constraints. [...] For other storage engines, MySQL Server parses and ignores the FOREIGN KEY and REFERENCES syntax in CREATE TABLE statements."
Best regards,
Bill -
is the code complete ?
2007-07-10 13:38:15 RaagSrinivasan [View]
Bill,
I am not sure I understood your comment in the sense; as a developer what am I supposed to do to get over the tutorial not working?
Would you recommend that I change the SQL to
-- category_id int null,
which naturally solves the problem??
Ruby and Rails Newbie
-- Raag -
is the code complete ?
2007-07-11 05:57:47 Bill Walton | [View]
Hi Raag,
I'm sorry you're having a problem. This section of the feedback got a little tangled, but if you take a look at my reply a few items above, dated 2006-12-20 at 13:49:02, I think you'll find what you're looking for. Basically, the tutorial doesn't tell you to do what you're trying to do. Unfortunately, I didn't explicitly tell you not to do it either. Your code's not broken. It's just not complete for what you're trying to do. It becomes complete in Part 2.
Best regards,
Bill -
is the code complete ?
2007-07-12 14:32:45 RaagSrinivasan [View]
Thank you and a very nice tutorial.
-- Raag



I just realized that when we cut the tutorial into Part 1 and Part 2 we should have put a note telling the reader that, in fact, the recipe creation will not work at that point. It will fail for exactly the reason you're seeing. We told MySQL that there would be a foreign key. We haven't told Rails about it though. And we can't create a recipe until we do. That comes next. Sorry guys. You're going to have to wait for the second installment. Or...
If you just can't wait to enter a recipe, just take the foreign key constraint (and the field) out of the script.
Again, my apologies. The tutorial was written and reviewed as one (long) work. When we chopped it into two pieces for publication, we obviously didn't cut cleanly. Lesson learned.
Best regards and best wishes for a safe and happy holiday,
Bill