2013-05-21 3 views

답변

0

당신은 레일이 메타 태그에 객체를 포함하는 두 개의 플러그인 살펴해야 할 수 있습니다 :

메타 매직 : https://github.com/lassebunk/metamagic

헤드 라이너 : https://github.com/mokolabs/headliner

편집 : 메타 태그 보석에 대한

내가 일반적으로하는 것은 내가 돕는 메타 도우미를 쓰는 것이다. 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(:title, @article.title) %> 

그리고 당신의 레이아웃에

, 당신은 매개 변수없이 추가, 그래서 메타 태그를 뱉어 것이다 : 그래서 articles/show.html.erb에서 당신은 당신의보기의 상단에이를 추가 할 수 있습니다.

<%= meta(:title) %> 

더 우아한 솔루션 거기 그래도 난 당신을 내기 :

<%= meta %> 

또는 그것을 출력 개별 태그가 있습니다.

그러나 레일스에서 ​​이미 구현 된 것을 찾고 있다면 운이 없어진 것입니다.

감사합니다.

+0

감사합니다 - 메타 태그 보석을 사용하고 있습니다. 그것은 레일즈 객체를 키워드에 넣는 방법에 관한 문제입니다 ... – tessad

+0

요즘에는 키워드와 메타 태그가 더 이상 사용되지 않습니다. 주요 검색 엔진 제공 업체는이를 무시합니다 ... – Richlewis

0

이 나를 위해 일한으로 (메타 태그 보석을 사용하여)보기에이 시도 :

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

다음과 같은 형식으로 루비 내에서 추가하여 텍스트 형식으로 추가 키워드를 CAD ['keyword3']

관련 문제