Problem with scaffolding?
After a couple of days of being distracted by getting Ubuntu set up I am back at it. I’m still in Chapter 13 of the book. I have the 1st edition. After I run through the scaffolding instructions this is the code I get for the index page.
This however is not what is listed in the book and the rendered web page looks like this:
The table header entries are missing. When I add the code that is supposed to be there, according to the book, to the first <tr> section then it renders properly.
I am running into similar problems with another page where scaffolding doesn’t seem to be properly creating the rhtml to display all the contents of the page. For example on the new page, the form fields to create a new entry are missing. Is it the scaffolding that is causing the problem, am I doing something incorrectly or ?
Did you call the scaffold generator with the fields you wanted, or did you add them later? The correct call would be:
script/generate scaffold Entry title:string content:text
If you didn't include the field definitions for title and content, then the scaffold generator won't insert them into the views, because it doesn't know they exist. I can see that you have those fields in the database, but I'm wondering if you ran the generator, then added them to the migration manually.
If you included the fields as I did above, then Rails definitely goofed, and this is not what you should have in a scaffold. I'd try it again with a fresh rails application, and if it has the same problem, reinstall rails itself.
the scaffolding command I ran was 'ruby script/generate scaffold Entry'. The author of the book has responded that the version of the book I am using was written for Rails 1. I have Rails 2 installed. I think that might be adding to my difficulties.
Thanks for the reply Jaime.
No problem! The book I always recommend to people is Agile Web Development with Rails. Here's a link:
http://bit.ly/agile_rails
It's even available as a cheaper pdf download, although I prefer the real thing.