Skip to content

knaveofdiamonds/friendly_id

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FriendlyId

Modifies an ActiveRecord model such that an attribute other than id can be transparently used as a uri parameter.

Example

class User < ActiveRecord::Base
  friendly_id :username
end

User.find("rolandswingler") # => a User, (assuming that User exists)
User.find(1) # => still works as normal - you can still find by id

The urls generated for map.resources :user would be: /users/rolandswingler rather than /users/1

The attribute that you use as a friendly_id must exist and be unique - friendly_id generates the ActiveRecord validations for this.

TODO / LIMITATIONS

  • You can't search by multiple friendly_ids: User.find("rolandswingler","fredbloggs") # won't work
  • Your friendly_ids can't be purely numeric - they'll assumed to be standard ids.

Copyright (c) 2009 Roland Swingler, released under the MIT license

About

[ABANDONED] Rails plugin to simplify using attributes other than id in urls

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages