Skip to content

Instantly share code, notes, and snippets.

@robbyoconnor
Forked from jgaskins/articles_controller.rb
Created August 19, 2014 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbyoconnor/f014a93014988966f015 to your computer and use it in GitHub Desktop.
Save robbyoconnor/f014a93014988966f015 to your computer and use it in GitHub Desktop.
class ArticlesController < ApplicationController
# with ActiveRecord
def create
@article = Article.new(params[:article])
if @article.save
redirect_to @article, notice: 'Article created!'
else
render :new
end
end
# with Perpetuity
def create
@article = Article.new(params[:article])
if @article.valid?
article_mapper.insert @article
redirect_to @article, notice: 'Article created!'
else
render :new
end
end
# I memoize mappers to get the benefit of their identity map
def article_mapper
@article_mapper ||= Perpetuity[Article]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment