GithubHelp home page GithubHelp logo

johnantoni / acts_as_slugable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from coding-bunny/acts_as_slugable

0.0 1.0 0.0 11 KB

Gem version of the old acts_as_slugable Rails 1.x plugin (usable on rails 5)

License: MIT License

Ruby 100.00%
rails ruby-on-rails slug

acts_as_slugable's Introduction

Acts as slugable readme

Generates a URL slug based on a specific fields (e.g. title).

Original repo: github.com/alexdunae/acts_as_slugable

Fixed for Rails 5

A url slug is a string derived from a specific field which can the be used in a URL. For instance, a page with the title My page would have a URL slug of my-page.

The slug is generated on save and create actions. If the field has an existing URL slug (like when editing an existing record) the URL slug is preserved.

URL slugs are unique within the specified scope (or all records if no scope is defined). If the slug already exists within the scope, -n is added (e.g. my-page-0, my-page-1, etc…

Installation

Add this to your Gemfile:

gem 'acts_as_slugable', git: 'https://github.com/johnantoni/acts_as_slugable.git'

Usage examples

In your target table, add a column to hold the URL slug.

With scope

class Page < ActiveRecord::Base
  acts_as_slugable :source_column => :title, :slug_column => :url_slug, :scope => :parent
end

Without scope

class Post < ActiveRecord::Base
  acts_as_slugable :source_column => :title, :slug_column => :url_slug
end
link_to @page.title, :action => 'show', :url_slug => @page.url_slug

Testing

The unit tests for this plugin use an in-memory sqlite3 database (www.sqlite.org/).

To execute the unit tests run the default rake task (rake). To execute the unit tests but preserve to debug log run rake test.

Credits

Created by Alex Dunae (dunae.ca/), 2006-09, though it takes a village to raise a plugin:

Thanks to Andrew White (pixeltrix.co.uk/) for fixing a conflict with acts_as_list.

Thanks to Philip Hallstrom (pjkh.com/) for pointing out some redundant code.

Thanks to Arne De Herdt (github.com/NekoNova) for making this a gem.

Thanks to Isoptope (isotopedev.com/) on Stackoverflow for resolving the query Issue.

acts_as_slugable's People

Contributors

johnantoni 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.