Skip to content

Instantly share code, notes, and snippets.

@haldun
Created November 11, 2012 17:48
Show Gist options
  • Save haldun/4055668 to your computer and use it in GitHub Desktop.
Save haldun/4055668 to your computer and use it in GitHub Desktop.
decent exposure with sti
class PostsController < ApplicationController
respond_to :html, :json
expose(:posts) { post_type.scoped }
expose(:post_type) { params[:type].constantize }
expose(:post) do
if id = params[:id]
posts.find id
else
post_type.new params[post_type.name.downcase.to_sym]
end
end
def index
respond_with posts
end
def new
end
def edit
end
def show
respond_with post
end
def create
if post.save
end
respond_with post
end
def update
if post.save
end
respond_with post
end
def destroy
post.destroy
respond_with post
end
end
resources :texts, controller: 'posts', type: 'Text'
resources :rsses, controller: 'posts', type: 'Rss'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment