SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict eskuel's Avatar
    Join Date
    Apr 2003
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Same template - Multiple Controllers

    I've just started playing with Ruby on Rails, so I'm sorry if this is a newb question

    I have 4 sections of an app im creating, and each section has a seperate controller. I would like to use the same template for all 4 controllers, rather than creating 4 templates all the same.

    I know there is a way to do this, I just want to know the best way to approach it.

    Thanks!

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    FL
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To effectivly use the same layout for a bunch of controllers, create a layout in the views/layouts folder called index, or whatever you choose. Code it how you would a normal HTML page, and add <%= @content_for_layout %> where you want all the page content to go.

    Then, Add this after your class controllername < ApplicationController line in the controllers you want to use the same layout with:
    Code:
    layout "index"
    (or whatever you named the layout file in views/layouts).

    You would still create your individual action views in their appropriate view folder, but now all the content will be wrapped in the layout file.

    Might seem a bit confusing at first, just give it a try, also, check the Rails wiki (http://wiki.rubyonrails.org/rails) for some really helpful info.
    Eric A.
    Founder and CEO, XMG Networks, Inc.
    XMG Services: Web 2.0 Photo Management and Sharing | Web Hosting
    Personal Blog: From Two 2 Twelve

  3. #3
    SitePoint Addict eskuel's Avatar
    Join Date
    Apr 2003
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks very much XMG-Eric, that worked perfectly

  4. #4
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to use the same layout throughout your app, you can just create a layout called application.rhtml in the layouts folder.

  5. #5
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also declare what template to use in your controller with render.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?


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
  •