This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Thu May 01 19:02:37 -0700 2008 | |
| |
README.markdown | Tue Sep 30 08:38:03 -0700 2008 | |
| |
Rakefile | Thu May 01 19:02:37 -0700 2008 | |
| |
init.rb | ||
| |
lib/ | ||
| |
test/ |
README.markdown
SaltySlugs
Abstraction of word-based slugs for URLs, w/ or w/o leading numeric IDs.
Installation
- Using Rails 2.1+
./script/plugin install git://github.com/norbauer/salty_slugs.git
Instructions
- SaltySlugs defaults to
titleas thesource_column,slugas theslug_column, and prepends the model ID. Upon creating/updating a record, the plugin will sluggify thesource_columnwhen theslug_columnis empty, otherwise it will sluggify theslug_columnunless theslug_syncoption is set to true (defaults to false).
class Post < ActiveRecord::Base has_slug end post = Post.create(:title => "Do Not Mix Slugs and Salt!") @post.to_param => '23-do-not-mix-slugs-and-salt'
- You can also overwrite the defaults
class Product < ActiveRecord::Base has_slug :source_column => :name, :slug_column => :permalink, :prepend_id => false end @product = Product.create(:name => "Salt and Pepper Shaker") @product.to_param => 'salt-and-pepper-shaker'
- Use the
slugged_findclass method in your controllers, smart enough to modify the search conditions if prepending ID is found or not.slugged_findis capable of accepting standardActiveRecord::Base#findoptions as a second parameter. If no records are found,ActiveRecord::RecordNotFoundis raised to match behavior ofActiveRecord::Base#find.
class PostsController < ApplicationController
def show
@post = Post.slugged_find(params[:id])
# or optionally with an eager-load
@post_with_author = Post.slugged_find(params[:id], :include => :author)
# catch exceptions if post is not found
rescue ActiveRecord::RecordNotFound
flash[:error] = "Post not found"
redirect_to :action => :index
end
end
- If the
sync_slugoption is set to true, thesource_columnwill always be sluggified upon updating the record. This means that the slug will not be able to be manually edited, but will always be synchronized to thesource_column.
TODO
- Add a word/regexp blacklist, so that they are sliced out of a string when sluggified (for example to remove .com, .net, etc)
Copyright (c) 2008 Norbauer Inc, released under the MIT license
Written by Jonathan Dance and Jose Fernandez








