Use of scaffolding in the ONLamp Rails tutorial

L

Lyle Johnson

I'm going through Curt's excellent Rails tutorial (at
http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html) and getting
stuck around the point that I try to add a new row to the recipes
table by clicking the "Create" button. It seems like the basic
"scaffolding" approach isn't doing the right thing, because it never
adds a row to the database for the newly created recipe(s). Just
curious if anyone else is having trouble at this point in the
tutorial?
 
L

Lyle Johnson

I'm going through Curt's excellent Rails tutorial (at
http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html) and getting
stuck around the point that I try to add a new row to the recipes
table by clicking the "Create" button. It seems like the basic
"scaffolding" approach isn't doing the right thing, because it never
adds a row to the database for the newly created recipe(s). Just
curious if anyone else is having trouble at this point in the
tutorial?
 
D

David Heinemeier Hansson

I'm going through Curt's excellent Rails tutorial (at
http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html) and getting
stuck around the point that I try to add a new row to the recipes
table by clicking the "Create" button. It seems like the basic
"scaffolding" approach isn't doing the right thing, because it never
adds a row to the database for the newly created recipe(s). Just
curious if anyone else is having trouble at this point in the
tutorial?

Have a look in the log by doing something like "tail -f
log/development.log" -- then you'll be able to see all the SQL
statements being fired off and whether the request is coming in right.

If you have additional questions, please do come hang out on
#rubyonrails for real-time assistance or use the dedicated Rails
mailing list. You can read more about both on
http://wiki.rubyonrails.com.

Welcome to the Rails world!
--
David Heinemeier Hansson,
http://www.basecamphq.com/ -- Web-based Project Management
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://macromates.com/ -- TextMate: Code and markup editor (OS X)
http://www.loudthinking.com/ -- Broadcasting Brain
 
L

Lyle Johnson

Have a look in the log by doing something like "tail -f
log/development.log" -- then you'll be able to see all the SQL
statements being fired off and whether the request is coming in right.

I tried this before posting; the SQL statements (e.g. to INSERT the
new row(s) into the database) are never getting printed out.
If you have additional questions, please do come hang out on
#rubyonrails for real-time assistance or use the dedicated Rails
mailing list. You can read more about both on
http://wiki.rubyonrails.com.

I had been chatting with several of the guys on #rubyonrails about
this problem before finally giving in and posting a query here. ;) You
are of course correct that they were really helpful, and that's a good
resource for anyone to check out. We just weren't able to track down
the problem.

We *did* note that when I went out to the console and tried
instantiating a new Recipe object and then calling its save() method,
it *did* get added to the database; so the AR layer certainly seems to
be doing the right thing. Indeed, the form that was displayed in the
web browser (when I visited the recipe/new page) showed all of the
expected fields -- so it was getting the correct table description
from the database. But something was definitely breaking down when I'd
click the "Create" button. No *errors* were printed to
development.log; it's just that it didn't do what it was supposed to
do.
Welcome to the Rails world!

Thanks! After talking with the guys on #rubyonrails, it sounds like I
ultimately won't want to depend on the "scaffolding" feature anyways,
and so I regard this as just a temporary hiccup in my getting started.
I'm looking forward to learning more about how to use Rails over the
next few weeks. I was mainly checking in to see if, by chance, anyone
else had run into this particular problem with Curt's tutorial.

P.S. Apologies for the duplicate post that kicks off this thread.
There was an unusual delay before the first one showed up, and so I'd
resubmitted it to ruby-talk in the meantime...
 
T

Tim Sutherland

I'm going through Curt's excellent Rails tutorial (at
http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html) and getting
stuck around the point that I try to add a new row to the recipes
table by clicking the "Create" button. It seems like the basic
"scaffolding" approach isn't doing the right thing, because it never
adds a row to the database for the newly created recipe(s). Just
curious if anyone else is having trouble at this point in the
tutorial?

It worked for me.
 
B

bananafishbones

It worked for me.
Is it throwing an error at you? Make sure you've got the db set up
correcty - I had a problem using phpMyAdmin until I realized that id
needed to be set to auto_increment.
 
L

Lyle Johnson

Is it throwing an error at you? Make sure you've got the db set up
correcty - I had a problem using phpMyAdmin until I realized that id
needed to be set to auto_increment.

It wasn't throwing an error -- or, at the least, no error messages
were getting written to the development.log file. And as I mentioned
in an earlier message, the ActiveRecord layer does seem to do the
right thing in terms of inserting the new row into the database *if* I
use it outside of the Web application. So I think the database is
probably set up correctly.
 
C

Curt Hibbs

Lyle said:
It wasn't throwing an error -- or, at the least, no error messages
were getting written to the development.log file. And as I mentioned
in an earlier message, the ActiveRecord layer does seem to do the
right thing in terms of inserting the new row into the database *if* I
use it outside of the Web application. So I think the database is
probably set up correctly.

Perhaps the problem is your browser caching the pages. Try forcing a page
re-load. or exiting and restarting your browser.

Curt
 
L

Lyle Johnson

Perhaps the problem is your browser caching the pages. Try forcing a page
re-load. or exiting and restarting your browser.

I think I just now figured out what I was doing wrong. I was
mistakenly typing the controller name in uppercase letters, e.g.

http://localhost:3000/Recipe/new

instead of:

http://localhost:3000/recipe/new

In the former case, there's no error message (that was obvious to me)
printed to the development.log file -- other than, of course, the
application didn't behave as expected. ;)

I do not know enough about Rails yet to know if this is the kind of
error which Rails could have automatically detected and warned me
about. If nothing else, this might be a good one to add to the
"gotchas" list for Rails, if there is such a thing. ;)
Lyle
 
C

Curt Hibbs

Lyle said:
I think I just now figured out what I was doing wrong. I was
mistakenly typing the controller name in uppercase letters, e.g.

http://localhost:3000/Recipe/new

instead of:

http://localhost:3000/recipe/new

In the former case, there's no error message (that was obvious to me)
printed to the development.log file -- other than, of course, the
application didn't behave as expected. ;)

I do not know enough about Rails yet to know if this is the kind of
error which Rails could have automatically detected and warned me
about. If nothing else, this might be a good one to add to the
"gotchas" list for Rails, if there is such a thing. ;)

Yeah, I just recently became aware of this myself. I'll probably say
something about in part 2 of the tutorial.

Curt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top