The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Simply Rails 2 - Chapter 6 - Page 171 - Layout

I just bought Simply Rails 2.0 by Patrick Lenz and I'm following along.

Everything is going fine until it's time to create a layout and style sheet.

On page 169, it says:

Layouts should be stored in the app/views/layouts folder. A layout template can basically be given any name, as long as the file ends in .html.erb. If the filename is application.html.erb, Rails will adopt this as the default layout.

So, I did like the book said, and created an application.html.erb file and saved it in the app/views/layouts folder. I actually just copied and pasted from the code archive. As far as I can tell the version in the book and code archive are the same.

On page 170, it says:

<%= stylesheet_link_tag 'style' %>
This code generates the HTML that includes an external style sheet in the page. By passing the string style, we ensure that the <link> tag that's generated will point to the URL /stylesheets/style.css.

I created a style sheet using the code in the code archive and placed it in the public/stylesheets folder.

When I reload the page /stories/new the page looks exactly the same as before (like page 164)

I took a look at the source code and the following stylesheet is referenced: "/stylesheets/scaffold.css?1245114256" . I deleted this stylesheet hoping this would make a difference. Didn't make a difference.

The layout template and style are not being recognized by the web server. I come to this conclusion because the "shovell" heading doesn't display.

My guess is the real problem is the layout template not being recognized. But I have no clue how to "fix" this problem.

I'm guessing you're using a newer version of Ruby/Rails than when the book was written. I too experimented with scaffolding (back on pages 145-8), and then had to "undo" things, but I didn't have the same problem, so I'm guessing things changed since then.

Anyway, if you used

Code:

$ ruby script/generate scaffold Story name:string link:string

you may be able to use "destroy" to undo the efects. I don't know if the syntax requires "name" and "link", but I think this should work.

Scaffolding was definitely the problem. I put the following command in to destroy the scaffolding:

$ ruby script/destroy scaffold Story name:string link:string

The scaffold got destroyed, but then after that I didn't know what to do. (That's one weakness in the book is lack of explanation on how to recover if you make a mistake. Even simple mistakes.) So, I restarted right from the beginning but skipped the scaffold part. And it worked fine.

And Delameko, about your comment:

Do you have any other layouts in the layouts folder?

For example, if you have a stories controller, it will use stories.html.erb layout instead of application.html.erb if it exists.

I did have the stories.html.erb and if what you say is true then that means the book is not entirely accurate when it says it will always grab application.html.erb if it exists.

Layouts should be stored in the app/views/layouts folder. A layout template can basically be given any name, as long as the file ends in .html.erb. If the filename is application.html.erb, Rails will adopt this as the default layout.

Not as clear as it could be I guess, but a "default" is technically not the same as an "always use".