Well I''m new to Ruby on Rails and actually new to implementing xhtml layout into my apps. So right now I''m making each page a layout, but the layout is the same xhtml for every single page. The problem is I have a menu, and the links for the menu are changing. The copyright notice could change, whatever it is. And so I have to change the layout of every single page. Is there a way I can store the layout in a location and get rails to retrieve that layout and implement it into the page (sort of like an "include"). And on this layout I have a title in the <title></title> tags. Each page has a different title, so is there I way I can make the title different for each page? And how would I do all this? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jake Fake wrote:> Well I''m new to Ruby on Rails and actually new to implementing xhtml > layout into my apps. So right now I''m making each page a layout, but the > layout is the same xhtml for every single page. The problem is I have a > menu, and the links for the menu are changing. The copyright notice > could change, whatever it is. And so I have to change the layout of > every single page. Is there a way I can store the layout in a location > and get rails to retrieve that layout and implement it into the page > (sort of like an "include"). And on this layout I have a title in the > <title></title> tags. Each page has a different title, so is there I way > I can make the title different for each page? And how would I do all > this?mmmm i don''t quite get the idea.... but let''s guess you wan''t to make in the same application several different looks. You have two levels of abstraction for your pages. 1) Layouts. They appear in app/views/layouts. Simply make a layout with the common things in every page. For example, here is a main.html file in the layouts dir: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /> <meta name="author" content="Emmanuel Oga" /> <title><%= @title></title> <%= javascript_include_tag :defaults %> </head> <body> <%= yield :layout %> </body> </html> Notice two things: First, <title><%= @title></title>. Now in your controller, you can set an @title variable and assign to it whatever title you want. Second: <%= yield :layout %>. This means: Put in here te generated page template. What generated page template? That depends on your controller. Lets say you have a "Main" Controller: class MainController < ApplicationController layout ''main'' # As rails uses convention over configuration, this is not # a necesity, why? because the template has the same name # as the controller, but you can put it or change it if # you want. i.e: create a foo.rhtml page in the # layout dir, then put layout ''foo'' and tada! def index @title= "THIS IS THE TITLE OF THE PAGE" end end Now, if you browse to your application url, let''s say http://localhost:3000/main/index, you acces to your Main Controller, the index action. So rails looks for a index.rhtml file in the app/views/main directory, renders that file and the result is put on the place you indicated with the <%= yield :layout %> syntax. So, you want to put a different look for every page? Create a controller for every page you want, make as many layouts as necesary to change the looks, then work in the templates for the action in every controller. I think that''s it... :) Emmanuel Oga -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jake Fake wrote:> Well I''m new to Ruby on Rails and actually new to implementing xhtml > layout into my apps. So right now I''m making each page a layout, but the > layout is the same xhtml for every single page. The problem is I have a > menu, and the links for the menu are changing. The copyright notice > could change, whatever it is. And so I have to change the layout of > every single page. Is there a way I can store the layout in a location > and get rails to retrieve that layout and implement it into the page > (sort of like an "include"). And on this layout I have a title in the > <title></title> tags. Each page has a different title, so is there I way > I can make the title different for each page? And how would I do all > this?Also be sure to investigate the use of css for customizing your pages: http://www.csszengarden.com/ There, a single page content is styled in a lot of different ways, with amazing results! You can implement that in rails using different css files in the layout, and changing the css using the same technique as with the title solution. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alright, thanks a lot :) I knew the layouts thing in number one but number two sor of opened a new door into rails for me. Thanks for all your help =) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Also read this blog post: http://errtheblog.com/post/28 It shows many good exampls on how to implement changing sidebars (e.g. wih different links as you said) for each controller or action into one single main layout. On 15 Jun., 22:51, Jake Fake <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Alright, thanks a lot :) I knew the layouts thing in number one but > number two sor of opened a new door into rails for me. Thanks for all > your help =) > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---