Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tonytonyjan/acts_as_permalinkable
A Rails plugin to genrate, validates permalink automatically.
https://github.com/tonytonyjan/acts_as_permalinkable
Last synced: about 1 month ago
JSON representation
A Rails plugin to genrate, validates permalink automatically.
- Host: GitHub
- URL: https://github.com/tonytonyjan/acts_as_permalinkable
- Owner: tonytonyjan
- License: mit
- Created: 2014-09-05T08:54:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-09-05T09:06:11.000Z (over 10 years ago)
- Last Synced: 2024-04-09T21:30:01.897Z (9 months ago)
- Language: Ruby
- Size: 141 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# Installation
# Gemfile
gem 'acts_as_permalinkable'# Usage
To generate parameterized string from `title` column to `slug` column before validation:
```ruby
class Post < ActiveRecord::Base
acts_as_permalinkable :title, :slug
end
```You probably want to change the way finding the record using `find_by`:
```ruby
def set_post
@post = Post.find_by(slug: params[:id])
end
```If there are both `name` and `permalink` columns, simplly write:
```ruby
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.