Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do it in Rails, not via javascript. Search Engines will not execute your javascript.</p> <p>What I usually do is write a meta helper that I simply stick in my ApplicationHelper, that looks like this:</p> <pre><code>def meta(field = nil, list = []) field = field.to_s @meta ||= { 'robots' =&gt; ['all'], 'copyright' =&gt; ['My Copyright'], 'content-language' =&gt; ['en'], 'title' =&gt; [], 'keywords' =&gt; [] } if field.present? @meta[field] ||= [] case list.class when Array then @meta[field] += list when String then @meta[field] += [list] else @meta[field] += [list] end case field when 'description' then content = truncate(strip_tags(h(@meta[field].join(', '))), :length =&gt; 255) else content = @meta[field].join(', ') end return raw(%(&lt;meta #{att}="#{h(field)}" content="#{h(content)}"/&gt;)) else tags = '' @meta.each do |field, list| tags += meta(field)+"\n" end return tags.rstrip end end </code></pre> <p>You can simply set meta tags in your views, by adding a call to meta() in it. So in an <code>articles/show.html.erb</code> you might add this to the top of your view:</p> <pre><code>&lt;% meta(:title, @article.title) %&gt; </code></pre> <p>And in your layouts, you add it without any parameters, so it'll spit out the meta tags.</p> <pre><code>&lt;%= meta %&gt; </code></pre> <p>Or have it output an individual tag:</p> <pre><code>&lt;%= meta(:title) %&gt; </code></pre> <p>I bet you there's more elegant solutions, though. But if you were looking for something already implemented in Rails you're out of luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload