Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 16th, 2010, 11:47 PM
orvn orvn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Location: Toronto, Canada
Posts: 5 orvn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 11 m 7 sec
Reputation Power: 0
Rails: Modifying <head> to include various metas and title tags

Hello,

I've been learning Ruby these past few days and I'm really liking it. I'm still sort of confused by rails.

I'm trying to integrate a block of meta tags (along with one title tag) into the header of each one of my pages.
The tags & title for every page are different.

Based on the ERB template mechanism that's already running on this site, the path:
...WEBSITE/stable/app/views/main

contains ERB's of all my html files: index.html.erb, about.html.erb, contact.html.erb, etc.

...WEBSITE/stable/app/views/layouts, I find a file named application.html.erb containing the following:

PHP Code:
<%= yield :extra_header_tags %>     
<%= 
stylesheet_link_tag 'jquery.lightbox-0.5' %>     
<%= 
stylesheet_link_tag 'style.css' %> 
    <%= 
yield :stylesheets %>       
<%= 
javascript_include_tag ['jquery''jquery.lightbox-0.5''java.js'] %>     <%= yield :javascripts %>    
<%= 
yield %> 


What is this <%= yield :extra_header_tags %>?
And how do I integrate my meta's in such a way that they're different for every page?
I guess I'm supposed to define some variables and then point them to someplace but I'm not sure how, any help would be very welcome.
Thanks!

(sorry for being such a n00b)

Reply With Quote
  #2  
Old November 14th, 2010, 07:50 PM
krenovkid krenovkid is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 3 krenovkid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 22 sec
Reputation Power: 0
Send a message via AIM to krenovkid
The yield :extra_header_tags tells Ruby to yield to that block when the page is parsed. What you want to do in each template is add the following:
<% content_for :extra_header_tags do %>
enter your custom title, etc here...
<% end %>

What Ruby will do is when it finds that content_for block it will inject it's contents into the matching yield mentioned above

Reply With Quote
  #3  
Old November 24th, 2010, 10:59 AM
robert_head robert_head is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 7 robert_head User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 16 sec
Reputation Power: 0
Title tag

You could drop this in your layout.

html Code:
Original - html Code
    <title><%= page_title %></title>


And then define the page title in a method in application_helper.rb

Or like this:

html Code:
Original - html Code
    <title><%= @page_title %></title>


In which case, you'd set @page_title in every controller.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Rails: Modifying <head> to include various metas and title tags

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap