Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

hridoy/acts_as_permalinkable

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

# Gemfile
gem 'acts_as_permalinkable'

Usage

To generate parameterized string from title column to slug column before validation:

class Post < ActiveRecord::Base
  acts_as_permalinkable :title, :slug
end

You probably want to change the way finding the record using find_by:

def set_post
  @post = Post.find_by(slug: params[:id])
end

If there are both name and permalink columns, simplly write:

class Post < ActiveRecord::Base
  acts_as_permalinkable
  # same as `acts_as_permalinkable :name, :permalink`
end

What does it do?

  • Validates presence and uniqueness of target column.
  • Generate parameterized string from source column to target column before validation if the target colmn is blank.
  • Override to_param, returnes the value of target column.
  • If the value of source column is not ASCII, a random string is generated insteadly.

About

A Rails plugin to genrate, validates permalink automatically.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 68.5%
  • HTML 23.0%
  • CSS 5.9%
  • JavaScript 2.6%