Created
January 26, 2012 19:46
-
-
Save justinwiley/1684659 to your computer and use it in GitHub Desktop.
DCI + Rails new and create
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
---role | |
module BookSeller | |
end | |
---context | |
class AddingBookContext | |
attr_accessor :user, :book | |
def initialize(user_id) | |
@user = User.find(user_id) | |
@book = Book.new(:user => @user) | |
@user.extend BookSeller | |
end | |
def execute(params) | |
@book.update_attributes(@bookparams) | |
end | |
end | |
---controller | |
class BookController < ApplicationController | |
before_filter :create_context, :only => [:new,:create] | |
def new | |
@book = @adding_book_context.book | |
end | |
def create | |
@adding_book_context.execute(params) | |
end | |
private | |
def create_context | |
@adding_book_context = AddingBookContext.new(current_user.id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment