Skip to content

Instantly share code, notes, and snippets.

@justinko
Created January 9, 2012 08:03
Show Gist options
  • Save justinko/1581812 to your computer and use it in GitHub Desktop.
Save justinko/1581812 to your computer and use it in GitHub Desktop.
class PostsController < ApplicationController
before_filter :post, only: :create # this feels like it's "posting", not setting a post
helper_method :post
def create
post.save
end
def post
@post ||= Post.new(params.fetch(:post) {{}})
end
end
# Imply the before_filter isn't "posting", but setting the post
class PostsController < ApplicationController
before_filter :set_post, only: :create
helper_method :post
def create
post.save
end
def post
@post ||= Post.new(params.fetch(:post) {{}})
end
alias :set_post :post
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment