# Problem understanding scaffolds

**URL:** <https://www.ruby-forum.com/t/problem-understanding-scaffolds/172691>\
**Category:** Rails\
**Created:** [July 25, 2009, 8:34pm UTC](https://www.ruby-forum.com/t/problem-understanding-scaffolds/172691 "2009-07-25T20:34:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iggybaseball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ed8c4c/32.png) [@iggybaseball](https://www.ruby-forum.com/u/iggybaseball)\
**Post date:** [July 25, 2009, 8:34pm UTC](https://www.ruby-forum.com/t/problem-understanding-scaffolds/172691/1 "2009-07-25T20:34:55Z")

</div>

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 B… 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. 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. I’m assuming that I have to  
add code to the scaffold to show these forms, is this true? Otherwise  
I’m just adding blank entries.

I am currently using  
Rad Rails 1.5.0.025739  
Ruby 1.8.6  
and I believe Rails 2.2

Any suggestions on what I’m missing?

---

<div class="post-metadata">

**Author:** ![iggybaseball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ed8c4c/32.png) [@iggybaseball](https://www.ruby-forum.com/u/iggybaseball)\
**Post date:** [July 26, 2009, 12:34am UTC](https://www.ruby-forum.com/t/problem-understanding-scaffolds/172691/2 "2009-07-26T00:34:22Z")

</div>

Laim B. 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 B…

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. 🙂

> 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  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![iggybaseball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ed8c4c/32.png) [@iggybaseball](https://www.ruby-forum.com/u/iggybaseball)\
**Post date:** [July 26, 2009, 1:50am UTC](https://www.ruby-forum.com/t/problem-understanding-scaffolds/172691/3 "2009-07-26T01:50:32Z")

</div>

Laim B. wrote:  
[…]

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

It’s not so much a question of breaking compatibility as of introducing  
better ways to do things. Rails is constantly introducing new shortcuts  
and abstractions, so if you’re using an old version’s way of doing  
things, you may be working too hard.

> Do you have a link for the site?

Um, you could have found it in about 5 seconds with Google. I think  
it’s [http://guides.rubyonrails.org](http://guides.rubyonrails.org) .

> 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?

Probably. But why don’t you read them and find out?

[…]

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

Great. Are you looking at the right database for the environment you’re  
running in (test, dev, or production)? If so, then just use your  
version control system (you _are_ using one, right?) to roll back to  
before you generated the scaffold, and run script/generate scaffold  
again.  
[…]

> 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?

Yes.  
[…]

> 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,

That’s why I recommend something like KomodoEdit. It is helpful without  
forcing your hand.

> but the easiness becomes  
> a handicap and when something doesn’t work, you have more trouble  
> figuring out why.

Often true. Some types of automated tools (HTML editors are another  
good example) are more helpful when you understand what’s being  
automated.

> > > 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?

rails -v will tell you what version will get put into a new app.  
script/about will tell you what your app is using.

> > ## Best,
> > 
> > Marnen Laibow-Koser  
> > [http://www.marnen.org](http://www.marnen.org)  
> > removed\_email\_address@domain.invalid
> 
> Thanks!

You’re welcome.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![iggybaseball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ed8c4c/32.png) [@iggybaseball](https://www.ruby-forum.com/u/iggybaseball)\
**Post date:** [July 26, 2009, 9:28am UTC](https://www.ruby-forum.com/t/problem-understanding-scaffolds/172691/4 "2009-07-26T09:28:55Z")

</div>

> > 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

---

<div class="post-metadata">

**Author:** ![iggybaseball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ed8c4c/32.png) [@iggybaseball](https://www.ruby-forum.com/u/iggybaseball)\
**Post date:** [July 26, 2009, 1:20am UTC](https://www.ruby-forum.com/t/problem-understanding-scaffolds/172691/5 "2009-07-26T01:20:34Z")

</div>

Marnen Laibow-Koser wrote:

> Laim B. 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 B…
> 
> 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. 🙂
> 
> > 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](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

Thanks!

---

<div class="post-metadata">

**Author:** ![iggybaseball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ed8c4c/32.png) [@iggybaseball](https://www.ruby-forum.com/u/iggybaseball)\
**Post date:** [July 26, 2009, 6:43pm UTC](https://www.ruby-forum.com/t/problem-understanding-scaffolds/172691/6 "2009-07-26T18:43:44Z")

</div>

Laim,

Scaffold will do it all (in a cookie cutter way), if given the right  
arguments.

script/generate scaffold User name:string profile:text  
NOTE:--------------------------------^ ----------------^

This single command will create a controller, model, views, and db/  
migration for the User model with fields for name and profile.

rake db:migrate  
script/server

point your browser at: [http://localhost:3000/users](http://localhost:3000/users) and follow the  
link to “New user”.

look at the files:

app/controllers/users\_controller.rb  
app/views/users/…  
app/models/user.rb  
db/migrate/…create\_users.rb
