I am trying to generate meta tags based on the page. The meta_block call
in somepage.html.erb sets :meta_block and it is correctly yielded in
application.html.erb (except that only the last line is output).
But when otherpage.html.erb is rendered, because I don''t call
meta_block
there is no meta content output. I thought the "|| meta_block" would
cause the helper to be called if :meta_block was not set.
How do I get all of the metat tags to be output on the page, and how do
I get it to happen if there are no per page keywords and description?
Thanks,
Matt
#application_helpers.rb
def meta_block(description = '''', keywords =
'''')
tag(''meta'', :''http-equiv'' =>
''Content-Type'', :content => ''text/html;
charset=utf-8'')
tag(''meta'', :''http-equiv'' =>
''Content-Language'', :content =>
''en-US,en'')
tag(''meta'', :name => ''description'',
:content => SITE[:DESCRIPTION] + description)
tag(''meta'', :name => ''keywords'',
:content => SITE[:KEYWORDS] + keywords)
tag(''meta'', :name => ''robots'',
:content => ''all'')
end
#somepage.html.erb
<% meta_block("My per page description.","keywords, for this,
page") %>
some page''s content
...
#otherpage.html.erb
other-page''s content
...
#application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>My Application</title>
<%= yield(:meta_block) || meta_block %>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="container">
<%= yield %>
</div>
</body>
</html>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
module LayoutHelper
def title(page_title, show_title = true)
content_for(:title) { h(page_title.to_s) }
@show_title = show_title
end
def show_title?
@show_title
end
def stylesheet(*args)
content_for(:head) { stylesheet_link_tag(*args) }
end
def javascript(*args)
content_for(:head) { javascript_include_tag(*args) }
end
end
<!DOCTYPE
html>
<html>
<head>
<title><%= content_for?(:title) ? yield(:title) :
"Untitled" %></
title>
<%= stylesheet_link_tag :application
%>
<%= javascript_include_tag :application
%>
<%= csrf_meta_tag
%>
<%= yield(:head)
%>
</
head>
<body>
<div
id="container">
<% if logged_in?
%>
Welcome <%= current_user.username
%>.
<%= link_to "Edit profile", edit_current_user_path %>
or
<%= link_to "Log out", logout_path
%>
<% else
%>
<%= link_to "Sign up", signup_path %>
or
<%= link_to "log in", login_path
%>.
<% end
%>
<% flash.each do |name, msg|
%>
<%= content_tag :div, msg, :id => "flash_#{name}"
%>
<% end
%>
<%= content_tag :h1, yield(:title) if show_title?
%>
<%= yield
%>
</
div>
</
body>
</html>
check this out
On Oct 18, 9:19 am, Matt Martini
<matt.mart...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I am trying to generate meta tags based on the page. The meta_block call
> in somepage.html.erb sets :meta_block and it is correctly yielded in
> application.html.erb (except that only the last line is output).
>
> But when otherpage.html.erb is rendered, because I don''t call
meta_block
> there is no meta content output. I thought the "|| meta_block"
would
> cause the helper to be called if :meta_block was not set.
>
> How do I get all of the metat tags to be output on the page, and how do
> I get it to happen if there are no per page keywords and description?
>
> Thanks,
>
> Matt
>
> #application_helpers.rb
> def meta_block(description = '''', keywords =
'''')
> tag(''meta'', :''http-equiv'' =>
''Content-Type'', :content => ''text/html;
charset=utf-8'')
> tag(''meta'', :''http-equiv'' =>
''Content-Language'', :content =>
''en-US,en'')
> tag(''meta'', :name =>
''description'', :content => SITE[:DESCRIPTION] +
description)
> tag(''meta'', :name => ''keywords'',
:content => SITE[:KEYWORDS] + keywords)
> tag(''meta'', :name => ''robots'',
:content => ''all'')
> end
>
> #somepage.html.erb
> <% meta_block("My per page description.","keywords, for
this, page") %>
> some page''s content
> ...
>
> #otherpage.html.erb
> other-page''s content
> ...
>
> #application.html.erb
> <!DOCTYPE html>
> <html>
> <head>
> <title>My Application</title>
> <%= yield(:meta_block) || meta_block %>
> <%= stylesheet_link_tag "application" %>
> <%= javascript_include_tag "application" %>
> <%= csrf_meta_tags %>
> </head>
> <body>
> <div id="container">
> <%= yield %>
> </div>
> </body>
> </html>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
To accept content, showing default if none, in your layout
<%= content_for?(:meta_block) ? yield(:meta_block) : meta_block $>
Called in your content.html.erb that uses the above layout.
<%= content_for(:meta_block) do $>
<%= meta_block("Yield", "Got it now!)%>
<% end %>
On Oct 18, 4:08 am, Nathan Wu
<cunhe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> module LayoutHelper
> def title(page_title, show_title = true)
> content_for(:title) { h(page_title.to_s) }
> @show_title = show_title
> end
>
> def show_title?
> @show_title
> end
>
> def stylesheet(*args)
> content_for(:head) { stylesheet_link_tag(*args) }
> end
>
> def javascript(*args)
> content_for(:head) { javascript_include_tag(*args) }
> end
> end
>
> <!DOCTYPE
> html>
> <html>
>
> <head>
> <title><%= content_for?(:title) ? yield(:title) :
"Untitled" %></
> title>
> <%= stylesheet_link_tag :application
> %>
> <%= javascript_include_tag :application
> %>
> <%= csrf_meta_tag
> %>
> <%= yield(:head)
> %>
> </
> head>
>
> <body>
> <div
> id="container">
> <% if logged_in?
> %>
> Welcome <%= current_user.username
> %>.
> <%= link_to "Edit profile", edit_current_user_path %>
> or
> <%= link_to "Log out", logout_path
> %>
> <% else
> %>
> <%= link_to "Sign up", signup_path %>
> or
> <%= link_to "log in", login_path
> %>.
> <% end
> %>
> <% flash.each do |name, msg|
> %>
> <%= content_tag :div, msg, :id => "flash_#{name}"
> %>
> <% end
> %>
> <%= content_tag :h1, yield(:title) if show_title?
> %>
> <%= yield
> %>
> </
> div>
> </
> body>
> </html>
>
> check this out
>
> On Oct 18, 9:19 am, Matt Martini
<matt.mart...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
>
>
>
>
> > I am trying to generate meta tags based on the page. The meta_block
call
> > in somepage.html.erb sets :meta_block and it is correctly yielded in
> > application.html.erb (except that only the last line is output).
>
> > But when otherpage.html.erb is rendered, because I don''t call
meta_block
> > there is no meta content output. I thought the "||
meta_block" would
> > cause the helper to be called if :meta_block was not set.
>
> > How do I get all of the metat tags to be output on the page, and how
do
> > I get it to happen if there are no per page keywords and description?
>
> > Thanks,
>
> > Matt
>
> > #application_helpers.rb
> > def meta_block(description = '''', keywords =
'''')
> > tag(''meta'', :''http-equiv''
=> ''Content-Type'', :content => ''text/html;
charset=utf-8'')
> > tag(''meta'', :''http-equiv''
=> ''Content-Language'', :content =>
''en-US,en'')
> > tag(''meta'', :name =>
''description'', :content => SITE[:DESCRIPTION] +
description)
> > tag(''meta'', :name =>
''keywords'', :content => SITE[:KEYWORDS] + keywords)
> > tag(''meta'', :name =>
''robots'', :content => ''all'')
> > end
>
> > #somepage.html.erb
> > <% meta_block("My per page description.","keywords,
for this, page") %>
> > some page''s content
> > ...
>
> > #otherpage.html.erb
> > other-page''s content
> > ...
>
> > #application.html.erb
> > <!DOCTYPE html>
> > <html>
> > <head>
> > <title>My Application</title>
> > <%= yield(:meta_block) || meta_block %>
> > <%= stylesheet_link_tag "application" %>
> > <%= javascript_include_tag "application" %>
> > <%= csrf_meta_tags %>
> > </head>
> > <body>
> > <div id="container">
> > <%= yield %>
> > </div>
> > </body>
> > </html>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.