SitePoint Sponsor

User Tag List

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

    Simply Rails 2 Chapter 6 Layout & stylesheet

    I have created the application.html.erb and style.css files as oulines on pages 168 - 171. Unfortunately.... these do not have any impact on what is displayed in the browser. Any help would be appreciated.

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't comment on how it is done in the book, but this is the general way it works:

    Layouts
    Live in app/view/layouts. By default, a views generated by a controller will automatically use a layout with the same name* as the controller if such a layout exists. So views used by a controller StoreController will automatically use a layout called store.rhtml or store.html.erb if the file exists.

    You can over-ride this behaviour by manually specifying the layout to use by adding something like this to your controller:
    Code:
    layout "another_layout"
    Which would point the controller at a layout file another_layout.rhtml or another_layout.html.erb

    Style sheet
    Style sheets are stored in public/stylesheets
    The style sheet used is usually defined within the layout with the method stylesheet_link_tag. By convention you'd use the controller name again. So in the Store example above you'd add this to the <head> section of your layout:
    Code:
    <&#37;= stylesheet_link_tag 'store' %>
    And this would create a link pointing at public/stylesheets/store.css.

    *Using the convention that a contoller 'named' Store has a class name of StoreController and file name store_controller.rb.

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,053
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    I'm working through the book now. In
    ....shovell\app\views\layouts\application.html.erb
    Code Ruby:
    <title>Shovell</title>
     
        <%= javascript_include_tag :defaults %>
        <%= stylesheet_link_tag 'style' %>
     
      </head>
    As ReggieB said, the "stylesheet_link_tag 'style'" should fetch the style.css file from the ....shovell\public\stylesheets folder.

    I'm wondering if you accidentally ran the "scaffold" line (page 146) and that's what you're seeing?

  4. #4
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help .... I figured it out.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice information dude.


Tags for this Thread

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
  •