GithubHelp home page GithubHelp logo

tomeduarte / activeadmin-seo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unmantained-activeadmin-plugins/activeadmin-seo

0.0 1.0 0.0 126 KB

SEO meta fields for ActiveAdmin resources

License: MIT License

Ruby 100.00%

activeadmin-seo's Introduction

Active Admin Seo

Add friendly_id and SEO meta fields to your ActiveAdmin resources.

Installation

Gemfile:

gem 'activeadmin-seo', github: 'nebirhos/activeadmin-seo'
gem "activeadmin-dragonfly", github: "stefanoverna/activeadmin-dragonfly"

Install and migrate:

rake activeadmin_seo:install:migrations
rake db:migrate

Usage

app/models/page.rb:

class Page < ActiveRecord::Base
  attr_accessible :title, :content
  has_seo_meta :title
end

app/admin/page.rb:

ActiveAdmin.register Page do
  form do |f|
    # ...
    f.seo_meta_inputs
    # ...
  end
end

Model options

Default options

has_seo_meta :field, tree: false, as: nil

Assign a role for editing Meta:

has_seo_meta :field, as: :admin

Adds url helper methods (see Nested Routes Handling below):

has_seo_meta :field, nested: true

Form helper options

Default options

f.seo_meta_inputs slug_url_prefix: nil, open_graph_metas: false, basic_metas: false

Include all basic metas fields (title/description/keywords) and all open graph metas fields (title/type/url/image)

f.seo_meta_inputs basic_metas: true, open_graph_metas: true

Include only basic metas title/description fields and open graph meta title/image fields

f.seo_meta_inputs basic_metas: [:title, :description],
                  open_graph_metas: [:title, :image]

f.seo_meta_inputs basic_metas: ['title', 'description'],
                  open_graph_metas: ['title', 'image']

f.seo_meta_inputs basic_metas: {
                    title: true,
                    description: true
                  },
                  open_graph_metas: {
                    title: true,
                    image: true
                  }

View Helpers

<%= seo_meta_tags(@page.seo_meta, title: page.title) %>

Nested Routes Handling

Often you need to route objects organized as a tree (eg. a Page resource). To simplify the routes management ActiveAdmin Seo provides these methods:

app/controllers/pages_controller.rb:

def show
  @page = Page.find_by_url params[:url]
  render text: @page.url # "/path/to/my/page"
end

config/routes.rb:

get "*url" => "pages#show", constraints: ActiveAdmin::Seo::Routes.new(Page)

So a request to “/about/page” finds the page with slug “page” and parent slug “about”, but a request to “/about/non-existent/page” renders a 404 error without calling the controller.

Globalize3

You can use it with activeadmin-globalize3, just put the directive in the active_admin_translates block:

app/models/page.rb:

class Page < ActiveRecord::Base
  active_admin_translates :title, :content do
    has_seo_meta :title
  end
end

app/admin/page.rb:

ActiveAdmin.register Page do
  form do |f|
    # ...
    f.translated_inputs do |t|
      t.input :title
      t.input :content
      # ...
      f.seo_meta_inputs
    end
    # ...
  end
end

Copyright © 2012 Francesco Disperati, Cantiere Creativo See the file MIT-LICENSE for details.

activeadmin-seo's People

Contributors

jerefrer avatar nebirhos avatar spleenteo avatar stefanoverna avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.