Question on the latest rails book

Hi all,

I am learning rails by going through 3rd ed of the Rails book.
In page 153, after creating the user scaffold it says:
"Since this modified config/routes.rb, which is cached for performance
reasons, you will need to start the server."

This is confusing me, what changed config/routes.rb? The creation of the
scaffold?
But this is confusion because we have created several scaffolds before
for orders, line_items, etc and this was never told to us before. Why
now?

Cheers,

Paulo Matos

Paulo J. Matos wrote:

I am learning rails by going through 3rd ed of the Rails book.
In page 153, after creating the user scaffold it says:
"Since this modified config/routes.rb, which is cached for performance
reasons, you will need to start the server."

This is confusing me, what changed config/routes.rb? The creation of the
scaffold?
But this is confusion because we have created several scaffolds before
for orders, line_items, etc and this was never told to us before. Why
now?

These are two disjoint topics.

Firstly, a "scaffold generator" typically edits a few files. Use your
version controller to see what it did to routes.rb. (And if you don't have a
version controller, such as git or svn, install it _now_!)

Secondly, when you change a Model, Controller, or View, Rails knows to
reload the source when you go to the browser and refresh (usually F5).
However, Rails naturally can't extend this benefit to _all_ source.
Otherwise it could end up reloading all of Ruby's standard library and
everything! So routes.rb is one of the files you must bounce the server if
you edit.

Next, despite scaffolds will take you a long way, you must soon stop using
them, and start writing features directly. Learn that, with unit tests, and
you will be reading to roll with Rails!

Phlip wrote:
[...]

So routes.rb is one of the files you must bounce the server
if
you edit.

Unless you're using Rails 2.3, which (in dev mode) immediately
incorporates changes in the routes file.

Best,

Paulo J. Matos wrote:

I am learning rails by going through 3rd ed of the Rails book.
In page 153, after creating the user scaffold it says:
"Since this modified config/routes.rb, which is cached for performance
reasons, you will need to start the server."

This is confusing me, what changed config/routes.rb? The creation of the
scaffold?
But this is confusion because we have created several scaffolds before
for orders, line_items, etc and this was never told to us before. Why
now?

These are two disjoint topics.

Firstly, a "scaffold generator" typically edits a few files. Use your
version controller to see what it did to routes.rb. (And if you don't have a
version controller, such as git or svn, install it _now_!)

Definitely agree with this. I would suggest git, which has a bit of a
learning curve but will be time well spent.

Secondly, when you change a Model, Controller, or View, Rails knows to
reload the source when you go to the browser and refresh (usually F5).
However, Rails naturally can't extend this benefit to _all_ source.
Otherwise it could end up reloading all of Ruby's standard library and
everything! So routes.rb is one of the files you must bounce the server if
you edit.

This does not answer the OP's question as to why he got this message
this time but not previously. Is it possible that the server was
running this time so the message was produced, otherwise it is not
produced (though I am not sure the scaffold generator would know
that). Paulo, I wouldn't worry about it if I were you, just restart
if necessary and carry on.

Next, despite scaffolds will take you a long way, you must soon stop using
them, and start writing features directly. Learn that, with unit tests, and
you will be reading to roll with Rails!

--

I disagree with that, keep using the scaffold generator to add new
stuff, it is by far the easiest way of generating the files generally
needed. Then use this as the base on which to build your application
specific stuff. There may come a point at which it is easier to add
new stuff entirely by hand but I certainly have not got there yet.
Don't forget to commit your source to your version control system
after running the generator so you can look back and see what you
changed.

Colin

For what it's worth I am witrh Colin on this but this is covered in the
foot note on page 46 of the pdf

6. If instead you see a message to the effect of No route matches
"/say/hello", try stopping and
restarting your server, because something you have done caused Rails to
cache your configuration
information before the controller was created.

The point made on the page you are talking about (p159 on the pdf) I
guess is a hang over from previous vewrsions of the book that dealt with
old versions of rails but it's a good lesson to learn. Always restart
your server if you get unexpected results and after making a lot of
changes. It takes no time to do and can save a lot of heartache trying
to debug code that has no bugs!

Colin Law wrote:
[...]

I disagree with that, keep using the scaffold generator to add new
stuff, it is by far the easiest way of generating the files generally
needed. Then use this as the base on which to build your application
specific stuff.

Generally not, unless you happen to be creating apps which are very
close to the scaffold.

There may come a point at which it is easier to add
new stuff entirely by hand but I certainly have not got there yet.

Then either your applications are very unusual (or mine are, in the
other direction) or you're relying too much on a crutch. I agree
totally that the scaffold generator should not be relied on.

Don't forget to commit your source to your version control system
after running the generator so you can look back and see what you
changed.

Yes!

Colin

Best,