Permalink

Instalation

gem install permalink

Usage

Add the method call permalink to your model. Your model should have a permalink attribute.

class Page < ActiveRecord::Base
  permalink :permalink # Add your permalink column name here
end

If you don't want to use permalink, you can call 'some text'.to_permalink string method and manage the permalink process by yourself.

You can define the the attributes you want to use

class Page < ActiveRecord::Base
  permalink :title, :to_param => %w( permalink page)
end

The id will automatically be included

The above settings will generate something link 100-some-title-page. By overriding to_param method you don't have to change a thing on your app routes.

The permalink is generated by replacing letters like "ä" to "ae", "ß" to "ss", "æ" to "ae", etc... so you can use it with every word and get nice urls!

The permalink is created when before_validation callback is evaluated. This plugin also tries to generate a permalink when before_save callback is evaluated and the instance has no permalink set.

You can overwrite the permalink generation by setting the using the :overwrite_permalink attribute

@post.update_attributes(:overwrite_permalink => "this is my custom link")
# => @post.permalink = "1-this-is-my-custom-link"

To show an edit field wiith permalink value use

@post.permalink_value_without_id # => "this-is-my-custom-link"

License

Copyright (c) 2011 Nando Vieira, released under the MIT license

Modified 2014 - Florian Eck

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.