mindtonic/URL-Shortener
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
URL-Shortener
This mixin for ActiveRecord creates a YouTube like url extensions, obstensively masking your record's id number.
To use, add a migration to the desired model that creates a string called :passkey, and be sure you index it!
def change
add_column :my_table_name, :passkey, :string
add_index :my_table_name, :passkey
end
Then simply include the mixin in the model.
class MyModel < ActiveRecord::Base
include UrlShortener
...
end
The mixin will automatically save the passkey upon create.
It also provides a scope called :by_passkey that you can use as a finder method.
MyModel.by_passkey("eXaMp1E")