title: Integrating stripe with Devise
body: <p>I am following along with railscast #288 on stripe but I am having some difficulty with setting the stripe hidden token. I am using the most recent version of devise with simple form integration. </p>
  
  <p>Here is my Registrations Controller:</p>
  
  <pre><code>class RegistrationsController &lt; Devise::RegistrationsController
  
    def create
      build_resource 
      if resource.save_with_payment
        if resource.active_for_authentication?
          set_flash_message :notice, :signed_up if is_navigational_format?
          sign_in(resource_name, resource)
          respond_with resource, :location =&gt; after_sign_up_path_for(resource)
        else
          set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
          expire_session_data_after_sign_in!
          respond_with resource, :location =&gt; after_inactive_sign_up_path_for(resource)
        end
      else
        clean_up_passwords resource
        respond_with resource
      end
    end
  </code></pre>
  
  <p>My form for registering a new user:</p>
  
  <pre><code>&lt;%= simple_form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name), :html =&gt; {:class =&gt; 'well'} ) do |f| %&gt;
    &lt;%= f.error_notification %&gt;
    &lt;%= f.error_messages %&gt;
    &lt;h3 class="center"&gt;Create your credentials for logging in:&lt;/h3&gt;&lt;hr&gt;
    &lt;div class="inputs"&gt;
      &lt;%= f.input :email, :required =&gt; true  %&gt;
      &lt;%= f.input :password, :required =&gt; true %&gt;
      &lt;%= f.input :password_confirmation, :required =&gt; true %&gt;
    &lt;h3 class="center"&gt;Are you a Shipper or a Carrier?&lt;/h3&gt;&lt;hr&gt;
      &lt;%= f.input :role, :collection =&gt; User::ROLES, :as =&gt; :radio_buttons %&gt;
      &lt;%= f.input :stripe_card_token, :as =&gt; :hidden %&gt;
    &lt;/div&gt;
    &lt;h3 class="center"&gt;Your Credit Card Information:&lt;/h3&gt;&lt;hr&gt;
    &lt;fieldset&gt;
      &lt;div class="field"&gt;
        &lt;%= label_tag :card_number, "Credit Card Number" %&gt;
        &lt;div class="input-prepend inline-block"&gt;
        &lt;span class="add-on"&gt;&lt;strong&gt;#&lt;/strong&gt;&lt;/span&gt;
        &lt;%= text_field_tag :card_number, nil, name: nil %&gt;
      &lt;/div&gt;
      &lt;div class="field"&gt;
        &lt;%= label_tag :card_code, "Security Code on Back of Card (CVV)" %&gt;
        &lt;div class="input-prepend inline-block"&gt;
        &lt;span class="add-on icon-credit-card"&gt;&lt;/span&gt;
        &lt;%= text_field_tag :card_code, nil, name: nil, :size =&gt; 4  %&gt;
      &lt;/div&gt;
      &lt;div class="field"&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, end_year: Date.today.year+15 },
    { name: nil, id: "card_year" } %&gt;
      &lt;/div&gt;
      &lt;div id="stripe_error"&gt;
        &lt;noscript&gt;JavaScript is not enabled and is required for this form. First enable it in your web browser settings.&lt;/noscript&gt;
      &lt;/div&gt;
    &lt;/fieldset&gt;
    &lt;hr&gt;
    &lt;%= f.input :terms, :as =&gt; :boolean, label: "* I have read and agreed to the terms of service" %&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.button :submit, "Sign up", class: "btn-large icon-thumbs-up" %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I have a user model with the following attributes: </p>
  
  <pre><code>attr_accessible :email, :password, :password_confirmation, :remember_me, :role, :terms, :stripe_token, :stripe_card_token
  </code></pre>
  
  <p>And Finally the coffeescript to get this all to work correctly:</p>
  
  <pre><code>jQuery -&gt;
  Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
  subscription.setupForm()
  
  subscription = 
    setupForm: -&gt;
      $('#new_user').submit -&gt;
          $('input[type=submit]').attr('disabled', true)
          if $('#card_number').length
              subsciption.processCard()
              false
          else
              true
  
  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
          $('#user_stripe_card_token').val(response.id)
          $('#new_user')[0].submit()
      else 
          $('#stripe_error').text(response.error.message)
          $('input[type=submit]').attr('disabled', false)
  </code></pre>
  
  <p>When I go to create a new user my action controller is giving me the following error message:</p>
  
  <pre><code>undefined method `stripe_card_token' for #&lt;User:0x00000103fe7b90&gt;
  </code></pre>
  
  <p>However I don't think this should be possible since I have defined this method in my attr_accessible call in my user.rb model. Any explanation would be really helpful, as I think i am 90% of the way to being done with setting this up. </p>