Skip to content

Instantly share code, notes, and snippets.

@mguterl
Forked from krisleech/01-trips_controller.rb
Created February 15, 2013 18:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mguterl/4962199 to your computer and use it in GitHub Desktop.
Save mguterl/4962199 to your computer and use it in GitHub Desktop.
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
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