https://github.com/theopencms/friendly_id_pack
Friendly Id for Models
https://github.com/theopencms/friendly_id_pack
Last synced: 10 months ago
JSON representation
Friendly Id for Models
- Host: GitHub
- URL: https://github.com/theopencms/friendly_id_pack
- Owner: TheOpenCMS
- License: mit
- Created: 2017-05-29T19:52:21.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-01T10:42:40.000Z (almost 9 years ago)
- Last Synced: 2025-03-05T23:14:16.021Z (over 1 year ago)
- Language: Ruby
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# FriendlyIdPack
```ruby
class SlugIds < ActiveRecord::Migration
def change
[:pages, :posts].each do |table_name|
change_table table_name do |t|
t.string :slug, default: ''
t.string :short_id, default: ''
t.string :friendly_id, default: ''
end
end
end
end
```
```ruby
class Post < ActiveRecord::Base
include FriendlyIdPack::Base
end
post = Post.new
post.title = "Привет"
post.save
post.title # => "Привет"
post.slug # => "privet"
post.short_id # => "pt1263"
post.friendly_id # => "pt1263+privet"
Post.friendly_where(:privet) # => [post ...]
Post.friendly_first(:privet) # => post
```
### MIT
zykin-ilya@ya.ru 2014