Closed ryanb082 closed 10 years ago
Hi @ryanb082. That's a funky error. Could you paste your controller and routes?
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]
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
Change class TransactionController
to class TransactionsController
(note the s
)
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
Hm. Did you spell the permalink correctly? what happens if you try the find_by!
in a rails console
?
Undefined method for 'by!'
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?
Yes, it show's me all the products i put in. For pemalink, should i just make up one I didn't list any
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.
Okay great, I will be upgrading to mastering modern payments soon. Thank you for your help. Question, how much do you charge for consulting?
No problem! Could you email me at hi@petekeen.net about consulting?
Will do
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?