new stack! hello there ! i'm making sample event booking app, has event check out using stripe.
my set below
class event < activerecord::base belongs_to :user has_many :tickets, :inverse_of => :event, dependent: :destroy end class ticket < activerecord::base belongs_to :event, :inverse_of => :tickets end class booking < activerecord::base belongs_to :event belongs_to :ticket, :inverse_of => :bookings has_one :sale, :inverse_of => :booking end class sale < activerecord::base belongs_to :booking, :inverse_of => :sale belongs_to :ticket end class bookingscontroller < applicationcontroller before_filter :load_event before_filter :load_ticket def index @bookings = @event.bookings end def new @booking = booking.new end private def load_event @event = event.find(params[:event_id]) end def load_ticket @ticket = @event.tickets.find(params[:ticket_id]) end def booking_params params.require(:booking).permit(:buyer_name, :phone, :address, :order_quantity,:total_amount) end end class transactionscontroller < applicationcontroller before_filter :load_event before_filter :load_booking before_filter :load_ticket def new end def pickup @sale = sale.find_by!(guid: params[:guid]) @booking = @sale.booking end def complete @sale = sale.find_by!(guid: params[:guid]) @booking = @sale.booking end if sale.save stripecharger.perform_async(sale.guid) render json: { guid: sale.guid } else errors = sale.errors.full_messages render json: { error: errors.join(" ") }, status: 400 end end def status sale = sale.find_by!(guid: params[:guid]) render json: { status: sale.state } end private def load_event @event = event.find(params[:event_id]) end def load_booking @booking = @event.bookings.find(params[:booking_id]) end def load_ticket @ticket = @booking.ticket.find(params[:ticket_id]) end end #stripe checkout routes
i left out view minimal details within models . trying have user enter name, , quantity of ticket , submitin booking redirect transaction new, in can carry out sale model stripe check out.
my ultimate goal of bookings quantity input multiplied ticket price total amount carry through stripe. have suggestions on how improve break down. of modeling events, tickets, bookings check out type of example. sorry if how i'm breaking down noobish, i'm attempting wrap head around accomplishing this.
in transaction controller don't need find on @booking.ticket
def load_ticket @ticket = @booking.ticket.find(params[:ticket_id]) end
since @booking has 1 ticket, need @booking.ticket