0.0
No commit activity in last 3 years
No release in over 3 years
Aimbulance CMS
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 3.0.0
>= 3.1.3

Runtime

 Project Readme

MetaManager

Enable meta tags in your model

Install

  gem "meta_manager"

ActiveRecord:

  require 'meta_manager/orm/active_record'

  rake meta_manager_engine:install:migrations

Mongoid:

  require 'meta_manager/orm/mongoid'

Usage

  class Category < ActiveRecord::Base
    include MetaManager::Taggable
  end

  @category = Category.new
  @category.tag_title = 'category test title'
  @category.tag_keywords = "Some keywords"
  @category.tag_description = "Some description"

  @category.meta_tags.build(:name => "og:title", :content => 'category og:title')

  # create dynamic meta tags, who will be overwrited the same category tag names
  # only with @meta_dynamic=true in controller
  @category.meta_tags.build(:name => "og:title", :content => 'dynamic og:title - %{post.title}', :is_dynamic => true)
  @category.meta_tags.build(:name => "title", :content => '%{post.title} - %{post.notes}', :is_dynamic => true)

  @category.save

  # create post for dynamic example
  @post = Post.create(:title => 'post test title', :notes => 'post test notes')

Rendering example

At layouts/application.html.erb

  <head>
  <%= raw(render_meta_tags(@category)) %>
  <title><%= render_page_title(@category) %></title>

At controllers/posts_controller.rb

  before_action :find_category
  before_action :prepare_dynamic_page, :only => [:show]

  def index
    @posts = Post.order('id')
    respond_with(@posts)
  end

  def show
    @post = Post.find(params[:id])
    respond_with(@post)
  end

  protected

  def find_category
    @category = Category.first
  end

  # set @meta_dynamic true to turn on dymanic meta tags.
  def prepare_dynamic_page
    @meta_dynamic = true
  end

It will be generate meta tags and title for @category. In action show we wont to generate dynamic meta tags from instance @post. It means that meta tag 'og:title' and tag 'title' will be overwrited with attributes from instance @post.

Results

Action index:

  <meta content='Some keywords' name='keywords' />
  <meta content='Some description' name='description' />
  <meta content='category og:title' property='og:title' />
  <title>category test title</title>

Action show:

  <meta content='Some keywords' name='keywords' />
  <meta content='Some description' name='description' />
  <meta content='dynamic og:title - post test title' property='og:title' />
  <title>post test title - post test notes</title>

Test

  rake test

Copyright (c) 2012 Fodojo, released under the MIT license