Created
October 11, 2011 17:08
-
-
Save raphaelcm/1278700 to your computer and use it in GitHub Desktop.
Easy way to support custom (human-written) URLs (helpful with SEO) using friendly_id
This file contains 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
class BlogPost < ActiveRecord::Base | |
# This Model has, in addition to title and other usual fields, | |
# two fields for creating custom urls: | |
# | |
# :use_custom_url, :boolean | |
# :custom_url, :string | |
validates :title, :presence => true, :uniqueness => true | |
has_friendly_id :title_or_custom, :use_slug => true | |
protected | |
def title_or_custom | |
use_custom_url ? custom_url : title | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment