Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
ornerymoose / charges_controller.rb
Last active August 29, 2015 14:00
Net::OpenTimeout in ChargesController#create, execution expired. The error is referring to line 2 in this gist but I don't think anything is wrong with the code.
respond_to do |format|
CustomerMailer.registration_confirmation(@customer.email).deliver
format.html { redirect_to charge_path(@cart, {customer_id: @customer.id}) }
format.json { head :ok }
end
@ornerymoose
ornerymoose / charges_controller.rb
Last active August 29, 2015 14:00
When I have just @cart = order in customer everything works fine, but if I try to add another instance variable it does not work (I need to pass it @customer.email from the charges_controller.rb file).
class ChargesController < ApplicationController
after_filter :destroy_cart, :only => [:show]
def new
@cart = Cart.find(params[:id])
end
def create
<html>
<head>
<%= stylesheet_link_tag "products-index" %>
</head>
<body>
<div class="wrapper-index">
<div class="push-index"></div>
<div class="products-container">
<% @products.each_with_index do |product, index| %>
<div class="product-item-<%= index %>">
<html>
<head>
<%= stylesheet_link_tag "products-index" %>
</head>
<body>
<div class="wrapper-index">
<div class="push-index"></div>
<div class="products-container">
<% @products.each_with_index do |product, index| %>
<div class="product-item-<%= index %>">
@ornerymoose
ornerymoose / products_controller.rb
Created May 9, 2014 00:31
this is working locally, but on heroku/production (heroku logs) I get a: ActionView::Template::Error (undefined method `each_with_index' for nil:NilClass):. NOTE: the index action/view works just fine in production. Why is this?
class ProductsController < ApplicationController
before_action :set_product, only: [:show]
# GET /products
# GET /products.json
def index
@products = Product.all
@cart = current_cart
end
<html>
<head>
<%= stylesheet_link_tag "charges-new" %>
</head>
<body>
<%= form_tag charges_path(id: @cart.id) do %>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-description="One-time Charge"
data-name="MyCompany"
@ornerymoose
ornerymoose / customer_cart.html.erb
Last active August 29, 2015 14:01
.stripe-button-el is the button for checkout/payment. Say there is two cart items at 25dollars each, if you were to remove one item (new total: 25 dollars not 50), the .stripe-button-el will still have the 50dollar total.
<html>
<head>
<%= stylesheet_link_tag "customer-cart" %>
</head>
<body>
<div class="wrapper-customer-cart">
<div class="push-customer-cart"></div>
<div class="customer-cart-container">
<div class="cart_title">Shopping Cart</div>
<table id="checkout-table">
@ornerymoose
ornerymoose / .bash_profile
Created June 2, 2014 05:56
laptop bash profile
# PATH=$HOME/usr/local/bin:$PATH
# export PATH
export CC=/usr/bin/gcc-4.2
export PATH=$PATH:/Android/android-sdk-mac_x86/tools
# {{{
# Node Completion - Auto-generated, do not touch.
shopt -s progcomp
for f in $(command ls ~/.node-completion); do
<html>
<body id="customer-cart">
<div class="wrapper-customer-cart">
<div class="push-customer-cart"></div>
<div class="customer-cart-container">
<div id="cart-title">Cart</div>
<div class="line"><hr /></div>
<div class="empty-cart"></div>
<table id="checkout-table">
<tr style="font-weight: bold;" class="cart-table-header">
@ornerymoose
ornerymoose / customer_cart.html.erb
Last active August 29, 2015 14:04
the ajax is correctly updating the view, but its not actually modifying the database: which is an issue in regards to the total_price of the cart when the user goes to checkout
<% @cart.line_items.each do |item| %>
<tr><td><%= item.product.name %></td>
<td><%= item.size %></td>
<td><%= item.color %></td>
<td><%= item.quantity %></td>
<td><%= link_to 'Delete',
{ :controller => 'line_items', :action => 'destroy', :id => item.id },
{ :method => :delete, :remote => true, :class => 'delete-item'} %> </td>
<td>$<%= item.product.price %></td></tr>
<% end %>