Problem understanding scaffolds

Laim Bee wrote:

Hey everyone,

I am new to ROR. I have been reading "Begininng Ruby on Rails" by Steven Holznewr and "Ruby on Rails for Dummies" by Barry Burd.

Be careful of learning Rails from books. The Rails framework changes pretty fast, and book publishers can't always keep up.

I have been going through this a lot slower than I would like, because many of the examples don't work and I've been trying to glean information from both books to get them working.

Why not try the Rails Guides website instead, or in addition? It's excellent and up to date.

My current problem is this:

Following Chapter 9 in "Ruby on Rails for Dummies" we are trying to build a website for Photos. This website will interface with a mysql database. I have built out the database, created a model, created a database table, wrote some code in the migration code to create a column for filename and description, and created a scaffold.

When I launch the server and view my website for extension photos/new (creating a new photo in the database), I just see a button titled "Create". The book shows a screenshot of two text fields being created, one for filename and one for description.

You say you wrote the migration; did you remember to run it? Check the database and make sure that it has the fields you expect. If so, regenerate the scaffold.

Better yet, just forget that scaffolding exists and find a tutorial that doesn't rely on it. :slight_smile:

I'm assuming that I have to add code to the scaffold to show these forms, is this true?

No. The idea of the scaffold is that it generates a quick-and-dirty set of views and controller actions based on your database fields. It sounds like when you generated the scaffold, the generator script didn't see any fields in your DB table, so it didn't put any fields in the view.

[...]

I am currently using Rad Rails 1.5.0.025739

Please don't start learning Rails by using an IDE. The framework is not well suited to conventional IDEs, and does not really benefit from their use. Try a full-featured editor instead (I like KomodoEdit and jEdit; many Rails developers use TextMate).

Ruby 1.8.6 and I believe Rails 2.2

Why start off on an old version of Rails? 2.3.2 is current. Use it instead.

Best,

Marnen Laibow-Koser wrote:

Laim Bee wrote:

Hey everyone,

I am new to ROR. I have been reading "Begininng Ruby on Rails" by Steven Holznewr and "Ruby on Rails for Dummies" by Barry Burd.

Be careful of learning Rails from books. The Rails framework changes pretty fast, and book publishers can't always keep up.

Yea I noticed this and now I'm leery about buying more books. Does Rails break compatibility often?

I have been going through this a lot slower than I would like, because many of the examples don't work and I've been trying to glean information from both books to get them working.

Why not try the Rails Guides website instead, or in addition? It's excellent and up to date.

Do you have a link for the site? The reason that I want to learn Ruby on Rails is because I have developed a site in HTML/CSS. I want to add a very simple blog type application that lets a user enter text and create a blog (I know there are plenty of free blogging programs, but I want to build something simple for myself). I would also like visitors to leave simple comments. I figure this is a great project to learn and practice the fundamentals. I also figure this is a good project to practice using a database. Will these guides help me in this regard?

My current problem is this:

Following Chapter 9 in "Ruby on Rails for Dummies" we are trying to build a website for Photos. This website will interface with a mysql database. I have built out the database, created a model, created a database table, wrote some code in the migration code to create a column for filename and description, and created a scaffold.

When I launch the server and view my website for extension photos/new (creating a new photo in the database), I just see a button titled "Create". The book shows a screenshot of two text fields being created, one for filename and one for description.

You say you wrote the migration; did you remember to run it? Check the database and make sure that it has the fields you expect. If so, regenerate the scaffold.

When I go into MySQL Administrator, I see the columns in my table.

Better yet, just forget that scaffolding exists and find a tutorial that doesn't rely on it. :slight_smile:

I'm assuming that I have to add code to the scaffold to show these forms, is this true?

No. The idea of the scaffold is that it generates a quick-and-dirty set of views and controller actions based on your database fields. It sounds like when you generated the scaffold, the generator script didn't see any fields in your DB table, so it didn't put any fields in the view.

Does a scaffold look at the columns and put in the appropriate field? For example if it sees you have a column which is a string, will it display a textbox then?

[...]

I am currently using Rad Rails 1.5.0.025739

Please don't start learning Rails by using an IDE. The framework is not well suited to conventional IDEs, and does not really benefit from their use. Try a full-featured editor instead (I like KomodoEdit and jEdit; many Rails developers use TextMate).

I originally started off using notepad++ but switched over to using the ide when I had to jump into the dummies book and follow one of the tutorials. I'll try going back to my editor. The thing I liked about the IDE was that it's more visual and it's easier, but the easiness becomes a handicap and when something doesn't work, you have more trouble figuring out why.

Ruby 1.8.6 and I believe Rails 2.2

Why start off on an old version of Rails? 2.3.2 is current. Use it instead.

Is there a command I can run to check what version I have?

Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org

Thanks!

Why start off on an old version of Rails? 2.3.2 is current. Use it instead.

Is there a command I can run to check what version I have?

ruby script/about from inside your project root or gem list rails

hth