Skip to content

Instantly share code, notes, and snippets.

@stephenrichards
Created December 12, 2018 10:24
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 stephenrichards/ec1a37bc7cb04e04f00237f4973b0527 to your computer and use it in GitHub Desktop.
Save stephenrichards/ec1a37bc7cb04e04f00237f4973b0527 to your computer and use it in GitHub Desktop.
Thin controller using service
class ThinController < ApplicationController
def index
@cards = OysterCard.order(balance: :desc)
end
def show
end
def swipe_out
@card = OysteCard.find(params[:id])
authorize @card # uses a Pundit policy to determine whether or not the current user is authorised to update this card
service = SwipeOutService.new(@card, params[:swipe_out][journey_end_station_id))
service.call
if service.result == :ok
redirect_to card_show_path
else
flash[:alert] = service.alerts
render :swipe_out
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment