Acts As Urlnameable plugin

Plugin details

This plugin provides an easy way to give your ActiveRecord models clean urlnames, for use anywhere you don’t want to use a plain old integer id.

Websitehttp://gironda.org/acts_as_urlnameable/ Author Gabriel Gironda Tags url LicenseMIT

Documentation

Setting the url name
====================

The usage that will work for 80% of cases is this:

        class Article < ActiveRecord::Base
          acts_as_urlnameable :title
        end


This will format the value of the title attribute of the record to one suitable for use in a URL and save it. Further changes to title will not overwrite the url name. The value can then be accessed with +object.urlname+. If the url name already exists, an error will be added to the urlname attribute.

To allow overwrites of the url name, call acts_as_urlname with the following option:

        class Article < ActiveRecord::Base
          acts_as_urlnameable :title, :overwrite => true
        end


Validation
==============

The url name will now be overwritten if the value of title changes. To change the default validation message you can use the :message option:

        class Article < ActiveRecord::Base
          acts_as_urlnameable :title, :overwrite => true, :message => 'is unavailable.'
        end



Finding records
=============
Records can be located via the find_by_urlname method, like so:

        Article.find_by_urlname('some_urlname')

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 9 months ago