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
My Application <%= yield(:meta_block) || meta_block %> <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %>