2015-01-26 3 views
0

의 ActiveRecord :: RecordNotFound 저는 생각하는 법을 배우는 것에 완전히 익숙하지 않고, 문제에 부딪쳐서 레일스 튜토리얼 스트라이프를 따라 가면 안 될 것 같습니다. 내가 언급 한 것처럼, 나는 생각하는 법을 배우는 것에 아직 익숙하지 않고, 코드를 복사하고 붙여 넣지 않고 읽는 것,보고, 쓰지 만 튜토리얼을 따르고 있기 때문에 정확히 무엇이 엉망인지 알아낼 수 없다. 근육 기억을 구축하기 위해 밖으로. 아마 철자법 오류, 그러나, 나는 이중 검사. 시간 내 줘서 고마워.TransactionsController # new

class TransactionsController < 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 = parmas[:stripeToken] 

    begin 
    charge = Stripe::Charge.create(
     amount:  product.price, 
     currency: "usd", 
     card:  token, 
     description: params[:stipeEmail] 
    ) 
    @sale = product.sales.create!(
     email:  params[:stripeEmail], 
     stripe_id: charge.id 
    ) 
    redirect_to pickup_url(guid: @sale.guid) 
    rescue Stripe::CardError => e 
    # the card has been declined or 
    # some other error has occured 
    @error = e 
    render :new 
    end 
end 

def download 
    @sale = Sale.find_by!(guid: params[:guid]) 

    resp = HTTParty.get(@sale.product.file.url) 

    filename = @sale.product.file.url 
    send_data resp.body, 
    :filename => File.basename(filename), 
    :content_type => resp.headers['Content-Type'] 
end 
end 
+0

오류는 어디에 있습니까? 정확한 오류 역 추적 및 메시지를 표시하십시오. –

+0

하단의 [link] (https://www.masteringmodernpayments.com/read/basic_integration) 지침에 따라 [링크] (http : // localhost : 3000/buy/some_permalink)와 액션 컨트롤러 오류에 따르면,이 줄은 '@product = Product.find_by!'(' – Justin

답변

0

오류는 데이터베이스의 params[:permalink] 동일 permalinkProduct 검색 코드

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

의 덩어리에 있지만 기록은 존재하지 않으며 오류가 발생합니다. 당신은 오류가 발생하지 않습니다 !없이 find를 사용할 수 있지만 다음 @productnil

은 당신이 정말로 데이터베이스에 기록을 찾을 필요하거나 클래스의 새 인스턴스를 만들 필요가 있는가 일 것이다. 다음과 같이 사용할 수 있습니다.

def new 
    @product = Product.new # is this solution for you? 
end 
+0

솔직히, 확실하지 않습니다. 다시 완전히 완전히 새로운 라인 5에서 제품을 찾을 수 없다는 것입니다. 생각하는 법을 배우고, 레일 애플리케이션을 세우십시오. – Justin

관련 문제