Created
October 25, 2010 23:50
-
-
Save devth/646046 to your computer and use it in GitHub Desktop.
A simple, well-known permalink pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example showing how to add permalinks to a model | |
| rails g migration AddPermalinksToAssets permalink:string | |
| rake db:migrate | |
| # In models | |
| def to_param | |
| permalink | |
| end | |
| # Auto-create permalink based on asset's `name` field | |
| def before_validation | |
| self.permalink = self.name.parameterize | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment