Skip to content

Instantly share code, notes, and snippets.

@xenda
Created February 11, 2014 01:54
Show Gist options
  • Save xenda/8927922 to your computer and use it in GitHub Desktop.
Save xenda/8927922 to your computer and use it in GitHub Desktop.
# model
class Post < ActiveRecord::Base
after_create :set_permalink
def set_permalink
self.permalink ||= self.title.parameterize
self.save
end
end
# controller
class PostsController < ApplicationController
def show
@post = Post.where(permalink: params[:id]).first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment