masteringmodernpayments / book

Discussion group for Mastering Modern Payments
https://www.masteringmodernpayments.com
6 stars 2 forks source link

Circular dependency detected while autoloading constant TransactionsController #13

Closed ryanb082 closed 10 years ago

ryanb082 commented 10 years ago

I get this run time error when I try to go to /buy/som_permalink on my local host. Do I need to add route to the TransactionsController?

peterkeen commented 10 years ago

Hi @ryanb082. That's a funky error. Could you paste your controller and routes?

ryanb082 commented 10 years ago
class TransactionController < ApplicationController
  skip_before_action :authenticate_user!,
    only: [:new, :create]

def new @product = Product.find_by!( permalink: params[:permalink] ) end

def pickup @sale = Sale.find_by!(guid: params[:guid]) @product = @sale.product end

def create product = Product.find_by!( permalink: params[:permalink] ) token = params[:stripeToken]

begin
  charge = Stripe::Charge.crete(
    amount:      product.price,
    currency:    "usd",
    card:        token,
    description: params[:stripeEmail]
ryanb082 commented 10 years ago

Rails.application.routes.draw do resources :products

devise_for :users

get '/buy/:permalink', to: 'transactions#new', as: :show_buy post '/buy/:permalink', to: 'transactions#create', as: :buy get '/pickup/:guid', to: 'transactions#pickup', as: :pickup get '/download/:guid', to: 'transactions#download', as: :download

peterkeen commented 10 years ago

Change class TransactionController to class TransactionsController (note the s)

ryanb082 commented 10 years ago

I now get this error ActiveRecord:NotFound def new @product = Product.find_by!( permalink: params[:permalink] ) end

i put in some test products, I don't understand why i would get this error

peterkeen commented 10 years ago

Hm. Did you spell the permalink correctly? what happens if you try the find_by! in a rails console?

ryanb082 commented 10 years ago

Undefined method for 'by!'

peterkeen commented 10 years ago

Product.find_by!(permalink: "whatever-your-product-permalink-is") should return something (replace the whatever-your-product-permalink-is with your real permalink).

Also, if you say Product.all, does it give you what you expect?

ryanb082 commented 10 years ago

Yes, it show's me all the products i put in. For pemalink, should i just make up one I didn't list any

peterkeen commented 10 years ago

In the setup described in this chapter, every product needs a permalink attribute, which is a unique human-readable string describing the product. You can just make them up, but the Product records in the database need to have it set.

ryanb082 commented 10 years ago

Okay great, I will be upgrading to mastering modern payments soon. Thank you for your help. Question, how much do you charge for consulting?

peterkeen commented 10 years ago

No problem! Could you email me at hi@petekeen.net about consulting?

ryanb082 commented 10 years ago

Will do