SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,270
    Mentioned
    197 Post(s)
    Tagged
    3 Thread(s)
    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.
    Code:
    $ ruby script/destroy scaffold Story

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Thank you Mittineague and Delameko!

    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.

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,270
    Mentioned
    197 Post(s)
    Tagged
    3 Thread(s)
    It may be true that the book says
    Quote Originally Posted by jonlyles
    it will always grab application.html.erb if it exists
    somewhere, but I found this on page 169
    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".

  6. #6
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Scaffolding was the problem for me too.
    I was racking my brain recreating all the files, looking for typos. Thanks for the info.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •