title: Cannot get a custom Stripe form to work with Ruby on Rails
body: <p>I am attempting to get Stripe working with a credit card payment for a subscription. </p>
  
  <p>I am currently getting a ForbiddenAttributesError, logs are below.</p>
  
  <pre><code>ActiveModel::ForbiddenAttributesError
  
  Extracted source (around line #10):
  
    def create
      @subscription = Subscription.new(params[:subscription])
      if @subscription.save_with_payment
        redirect_to @subscription, :notice =&gt; "Thank you for subscribing!"
      else
  </code></pre>
  
  <p>Logs:</p>
  
  <pre><code>Processing by SubscriptionsController#create as HTML                                                                                                                                                                           
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"N58ei1EzQ+K4ATyJfSVOFIcZL96vML/wL3AWRuGAgH0=", "subscription"=&gt;{"stripe_card_token"=&gt;"tok_14pO112LeYog8mPkCsNDhIbK"}}                                                       
    User Load (0.5ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1                                                                                                                 
  Completed 500 Internal Server Error in 4ms                                                                                                                                                                                     
  
  ActiveModel::ForbiddenAttributesError (ActiveModel::ForbiddenAttributesError):                                                                                                                                                 
    app/controllers/subscriptions_controller.rb:10:in `create'                                                                                                                                                                   
  
  
    Rendered /home/action/.gem/ruby/2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.2ms)                                                                                             
    Rendered /home/action/.gem/ruby/2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.0ms)                                                                                         
    Rendered /home/action/.gem/ruby/2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.6ms)                                                                          
    Rendered /home/action/.gem/ruby/2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (28.1ms)     
  </code></pre>
  
  <p>subscriptions_controller.rb</p>
  
  <pre><code>class SubscriptionsController &lt; ApplicationController
  
      before_filter :authenticate_user!
  
      def new
          @subscription = Subscription.new
      end
  
    def create
      @subscription = Subscription.new(params[:subscription])
      if @subscription.save_with_payment
        redirect_to @subscription, :notice =&gt; "Thank you for subscribing!"
      else
        render :new
      end
    end
  
    def show
      @subscription = Subscription.find(params[:id])
    end
  
  
  end
  </code></pre>
  
  <p>subscription.rb</p>
  
  <pre><code>class Subscription &lt; ActiveRecord::Base
      belongs_to :user
  
      attr_accessor :stripe_card_token
  
      before_create :save_with_payment
  
      def save_with_payment
              customer = Stripe::Customer.create(
                  :card =&gt; stripe_card_token,
                  :description =&gt; "name",
                  :plan =&gt; 121,
                  :email =&gt; "email")
  
              self.stripe_customer_id = customer.id
              self.plan = 121
      end
  
  end
  </code></pre>
  
  <p>subscriptions.js.coffee</p>
  
  <pre><code># Place all the behaviors and hooks related to the matching controller here.
  # All this logic will automatically be available in application.js.
  
  jQuery -&gt;
    Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
    subscription.setupForm()
  
  subscription =
    setupForm: -&gt;
      $('#new_subscription').submit (e) -&gt;
        $('input[type=submit]').attr('disabled', true)
        subscription.processCard()
        return false
  
    processCard: -&gt;
      card =
        number: $('#card_number').val()
        cvc: $('#card_code').val()
        expMonth: $('#card_month').val()
        expYear: $('#card_year').val()
      Stripe.createToken(card, subscription.handleStripeResponse)
  
    handleStripeResponse: (status, response) -&gt;
      if status == 200
        $('#subscription_stripe_card_token').val(response.id)
        $('#new_subscription')[0].submit()
      else
        $('#stripe_error').text(response.error.message) 
        $('input[type=submit]').attr('disabled', false)
        false
  </code></pre>
  
  <p>new.html.erb</p>
  
  <pre><code>&lt;div class='panel panel-default'&gt;
  
      &lt;div class='panel-heading'&gt;
          &lt;h2&gt;Subscribe&lt;/h2&gt;
      &lt;/div&gt;
  
      &lt;div class='panel-body'&gt;
  
      &lt;%= form_for @subscription, :html =&gt; {:class =&gt; 'main-form'} do |f| %&gt;
  
          &lt;%= f.hidden_field :stripe_card_token %&gt;
  
          &lt;div id='stripe_error' class="alert alert-info" style='display:none'&gt;
          &lt;/div&gt;
  
  
          &lt;span class="help-block"&gt;Nothing is billed to your card for 7 days. &lt;b&gt;Guaranteed. &lt;/b&gt;
              &lt;br&gt;If you choose to continue after 7 days, only then will you be billed.&lt;/span&gt;
  
                &lt;div class='form-group'&gt;
                  &lt;%= label_tag :card_number, "Credit Card Number" %&gt;
                    &lt;%= text_field_tag :card_number, nil, name: nil, class: 'form-control input-box', :placeholder =&gt; 'Credit Card Number' %&gt;
                &lt;/div&gt;
  
          &lt;div class='row'&gt;
  
              &lt;div class="col-xs-6"&gt;
                  &lt;%= label_tag :card_code, "Security Code on Card (CVC)" %&gt;
                  &lt;%= text_field_tag :card_code, nil, name: nil, class: 'form-control input-box', :placeholder =&gt; 'Security Code on Card (CVC)' %&gt;
              &lt;/div&gt;
  
              &lt;div class="col-xs-6"&gt;
                  &lt;%= label_tag :card_month, "Card Expiration" %&gt;
                  &lt;%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %&gt;
                  &lt;%= select_year nil, {start_year: Date.today.year+1, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %&gt;
              &lt;/div&gt;
  
          &lt;/div&gt;
  
  
  
              &lt;div&gt;
                  &lt;%= f.submit "Subscribe", class: 'btn standard-button' %&gt;
              &lt;/div&gt;
  
  
          &lt;% end %&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>