2013-05-21 23 views
0

我想在我的關鍵字中包含一個rails對象以及直接文本,但代碼顯然不是正確的方法......我該怎麼做?在元標記中包含rails對象關鍵字

set_meta_tags :keywords => %w[keyword1 keyword2 #{params[:hospital]}] 

回答

0

你可能想看看兩個插件包括導軌在meta標籤對象:

元魔法:https://github.com/lassebunk/metamagic

頭部襯裏:https://github.com/mokolabs/headliner

編輯:對於元標記寶石

我通常做的是寫一個元幫助,我simp LY粘在我的ApplicationHelper,看起來像這樣:

def meta(field = nil, list = []) 
    field = field.to_s 
    @meta ||= { 
    'robots' => ['all'], 
    'copyright' => ['My Copyright'], 
    'content-language' => ['en'], 
    'title' => [], 
    'keywords' => [] 
    } 

    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 => 255) 
     else 
     content = @meta[field].join(', ') 
    end 

    return raw(%(<meta #{att}="#{h(field)}" content="#{h(content)}"/>)) 
    else 
    tags = '' 
    @meta.each do |field, list| 
     tags += meta(field)+"\n" 
    end 
    return tags.rstrip 
    end 
end 

你可以簡單地設置你的意見meta標籤,加入到它meta()通話。所以在articles/show.html.erb你或許會添加到您的視圖的頂部:

<% meta(:title, @article.title) %> 

而在你的佈局,你加它不帶任何參數,所以它會吐出meta標籤。

<%= meta %> 

還是有它輸出一個單獨的標籤:

<%= meta(:title) %> 

我敢打賭,你有更多的優雅的解決方案,雖然。

但是,如果你正在尋找一些已經在Rails中實現的東西,你倒黴了。

謝謝。

+0

謝謝 - 我正在使用meta-tags寶石。這是一個關於如何將rails對象放入關鍵字的問題...... – tessad

+0

關鍵字和元標記現在已被棄用,在您的頁面上擁有良好的內容就好像不是更有效。主要的搜索引擎提供商忽略它們... – Richlewis

0

在你看來試試這個,因爲它爲我工作(使用元標籤寶石):

<% keywords [[@modelname.keyword1], [@modelname.keyword2]] %> 

,你在下面的格式紅寶石內加入他們的CAD文本格式額外的關鍵字['keyword3']

相關問題