Skip to content

Instantly share code, notes, and snippets.

@codyeatworld
Created May 14, 2015 16:50
Show Gist options
  • Save codyeatworld/b30c965113b91968b255 to your computer and use it in GitHub Desktop.
Save codyeatworld/b30c965113b91968b255 to your computer and use it in GitHub Desktop.
module CurrentCheckout
extend ActiveSupport::Concern
included do
before_action :set_current_checkout
end
private
def set_current_checkout
@current_checkout = if session[:checkout] == 'buys'
current_group_buy_cart
elsif session[:checkout] == 'bros'
current_bro_cart
else
current_cart
end
end
end
class Checkout::DetailsController < ApplicationController
include CurrentCheckout
before_action :set_shipping_address
def show
end
def update
if @shipping_address.update_attributes(shipping_address_params)
redirect_to checkout_confirmation_url
else
render :show
end
end
private
def shipping_address_params
params.require(:shipping_address).permit(:full_name, :email, :street1, :street2, :city, :state, :zip, :phone, :residential, :country)
end
def set_shipping_address
@shipping_address = @current_checkout.shipping_address
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment