-
-
Save robbyoconnor/f014a93014988966f015 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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