Created
December 12, 2018 10:24
-
-
Save stephenrichards/ec1a37bc7cb04e04f00237f4973b0527 to your computer and use it in GitHub Desktop.
Thin controller using service
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 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