title: unsure where to put Stripe API call
body: <p>Been thinking about this problem for hours now, and I think it's because im misunderstanding some fundamental rails knowledge</p>
  
  <p>In <a href="https://stripe.com/docs/checkout/guides/rails" rel="nofollow">this intro Stripe guide</a>, they demonstrates the following code</p>
  
  <pre><code>def new
  end
  
  def create
    # Amount in cents
    @amount = 500
  
    customer = Stripe::Customer.create(
      :email =&gt; 'example@stripe.com',
      :card  =&gt; params[:stripeToken]
    )
  
    charge = Stripe::Charge.create(
      :customer    =&gt; customer.id,
      :amount      =&gt; @amount,
      :description =&gt; 'Rails Stripe customer',
      :currency    =&gt; 'usd'
    )
  
  rescue Stripe::CardError =&gt; e
    flash[:error] = e.message
    redirect_to charges_path
  end
  </code></pre>
  
  <p>My question is, do all the code in the <code>create</code> action have to reside within <code>create</code>? </p>
  
  <p>I am trying to follow through with the guide, but instead of only having one single product, I have multiples. So naturally I put the code within the <code>show</code> action.</p>
  
  <pre><code>class BooksController &lt; ApplicationController
  
      def index
          @books = Book.all
      end
  
      def show
          @book = Book.find(params[:id])
  
  
          customer = Stripe::Customer.create(
              :email =&gt; 'example@stripe.com',
              :card  =&gt; params[:stripeToken]
          )
  
          charge = Stripe::Charge.create(
              :customer    =&gt; customer.id,
              :amount      =&gt; @book.price,
              :description =&gt; 'Rails Stripe customer',
              :currency    =&gt; 'usd'
          )
  
          rescue Stripe::CardError =&gt; e
              flash[:error] = e.message
              redirect_to books_path
  
      end
  end
  </code></pre>
  
  <p>Now, whenever I try to access any show page (localhost:3000/books/1), it redirects to the <code>books_path</code>, which tells me there is some kind of CardError. </p>
  
  <p>What is going on here?</p>