-
-
Save mguterl/4962199 to your computer and use it in GitHub Desktop.
This file contains 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 TripsController < ApplicationController | |
class Action < ApplicationController::Action | |
end | |
class New < Action | |
expose(:trip) { Trip.new(params[:trip]) } | |
end | |
class Create < New | |
def call | |
CreateTrip.new(self).execute(current_user, params[:trip]) | |
end | |
def successful(trip) | |
redirect_to trip | |
end | |
def failed(trip) | |
render :action => :new | |
end | |
end | |
end |
This file contains 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 CreateTrip | |
def initialize(listener) | |
@listener = listener | |
end | |
def execute(user, attributes) | |
trip = Trip.new(attributes) | |
trip.user = user | |
if trip.save | |
listener.successful(trip) | |
else | |
listener.failed(trip) | |
end | |
end | |
private | |
attr_reader :listener | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment