title: Stripe Plan ID not saving to user
body: <p>I'm building a rails app that involves signing up customers to different plans. I'm using Rails and the gems Devise and Stripe, and Figaro. I have three plans, plan_id 1 is going to be admin and is free. plan_id 2 is basic, and free, and will allow customers to view the site but not interact, and plan_id 3 is subcription based. All forms work fine, and I am able to sign-up but in the console none of the users have plan_id's assigned to them? Their email addresses and passwords are stored but nothing else. Please help, i can't spot the problem!</p>
  
  <p>PagesController</p>
  
  <pre><code>class PagesController &lt; ApplicationController
      def home
          @admin_plan = Plan.find(1)
          @partner_plan = Plan.find(2)
          @paidsubscription_plan = Plan.find(3)
      end
  end
  </code></pre>
  
  <p>RegistrationsController</p>
  
  <pre><code>class Users::RegistrationsController &lt; Devise::RegistrationsController
  
    before_filter :select_plan, only: :new
  
    def create
      super do |resource|
        if params[:plan]
          resource.plan_id = params[:plan]
          if resource.plan_id == 3
            resource.save_with_payment
          else
            resource.save
          end
        end
      end
    end
  
    private  
    def select_plan
      unless params[:plan] &amp;&amp; (params[:plan] == '1' || params[:plan] == '2' || params[:plan] == '3')
        flash[:notice] = "Please select a valid membership plan."
        redirect_to root_url
      end 
    end
  end
  </code></pre>
  
  <p>models/user.rb</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
  
     belongs_to :plan
     attr_accessor :stripe_card_token
     def save_with_payment
      if valid?
        customer = Stripe::Customer.create(description: email, plan: plan_id, card: stripe_card_token)
        self.stripe_customer_token = customer.id
        save!
      end
    end
  end
  </code></pre>
  
  <p>schema.rb</p>
  
  <pre><code>ActiveRecord::Schema.define(version: 20150820123651) do
  
    create_table "plans", force: :cascade do |t|
      t.string   "name"
      t.decimal  "price"
      t.datetime "created_at"
      t.datetime "updated_at"
    end
  
    create_table "users", force: :cascade do |t|
      t.string   "email",                  default: "", null: false
      t.string   "encrypted_password",     default: "", null: false
      t.string   "reset_password_token"
      t.datetime "reset_password_sent_at"
      t.datetime "remember_created_at"
      t.integer  "sign_in_count",          default: 0,  null: false
      t.datetime "current_sign_in_at"
      t.datetime "last_sign_in_at"
      t.string   "current_sign_in_ip"
      t.string   "last_sign_in_ip"
      t.datetime "created_at",                          null: false
      t.datetime "updated_at",                          null: false
      t.integer  "plan_id"
      t.string   "stripe_customer_token"
    end
  
    add_index "users", ["email"], name: "index_users_on_email", unique: true
    add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  
  end
  </code></pre>
  
  <p>/views/devise/registrations/new.html.erb</p>
  
  <pre><code>&lt;div class="row"&gt;
    &lt;div class="col-md-4 col-md-offset-4"&gt;
      &lt;div class="well"&gt;
        &lt;% if params[:plan] == '3' %&gt;
          &lt;%= render 'paid' %&gt;
        &lt;% else %&gt;
          &lt;%= render 'basic' %&gt;
        &lt;% end %&gt;
  
  
        &lt;%= render "devise/shared/links" %&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>a basic ../views/pages/home</p>
  
  <pre><code>&lt;h1&gt;Home Page&lt;/h1&gt;
  
  &lt;div class="col-md-4"&gt;
     &lt;%= link_to "Admin Sign-Up", new_user_registration_path(plan: @admin_plan.id), class: "btn btn-info btn-lg btn-block" %&gt; 
  &lt;/div&gt;
  &lt;div class="col-md-4"&gt;
     &lt;%= link_to "Partner Sign-Up", new_user_registration_path(plan: @partner_plan.id), class: "btn btn-warning btn-lg btn-block" %&gt; 
  &lt;/div&gt; 
  &lt;div class="col-md-4"&gt;
     &lt;%= link_to "Paid Subscription Sign-Up", new_user_registration_path(plan: @paidsubscription_plan.id), class: "btn btn-success btn-lg btn-block" %&gt; 
  &lt;/div&gt;
  </code></pre>
  
  <p>/views/devise/registrations/_paid.html.erb</p>
  
  <pre><code>&lt;h2&gt;Sign up &lt;/h2&gt;
        &lt;%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %&gt;
          &lt;%= devise_error_messages! %&gt;
  
          &lt;div class="field form-group"&gt;
              &lt;%= f.label :email %&gt;&lt;br /&gt;
              &lt;%= f.email_field :email, autofocus: true, class: "form-control" %&gt;
          &lt;/div&gt;
  
          &lt;div class="field form-group"&gt;
              &lt;%= f.label :password %&gt;
              &lt;% if @minimum_password_length %&gt;
              &lt;em&gt;(&lt;%= @minimum_password_length %&gt; characters minimum)&lt;/em&gt;
              &lt;% end %&gt;&lt;br /&gt;
              &lt;%= f.password_field :password, autocomplete: "off", class: "form-control" %&gt;
          &lt;/div&gt;
  
          &lt;div class="field form-group"&gt;
              &lt;%= f.label :password_confirmation %&gt;&lt;br /&gt;
              &lt;%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %&gt;
          &lt;/div&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" %&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;%= label_tag :card_code, "Security Code on Card (CVV)" %&gt;
              &lt;%= text_field_tag :card_code, nil, name: nil, class: "form-control" %&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&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 class="actions form-group"&gt;
            &lt;%= f.submit "Sign up", class: "btn btn-info" %&gt;
          &lt;/div&gt;
        &lt;% end %&gt;
  </code></pre>
  
  <p>/views/devise/registrations/_basic.html.erb</p>
  
  <pre><code>&lt;%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %&gt;
          &lt;%= devise_error_messages! %&gt;
  
          &lt;div class="field form-group"&gt;
            &lt;%= f.label :email %&gt;&lt;br /&gt;
            &lt;%= f.email_field :email, autofocus: true, class: "form-control" %&gt;
          &lt;/div&gt;
  
          &lt;div class="field form-group"&gt;
            &lt;%= f.label :password %&gt;
            &lt;% if @minimum_password_length %&gt;
            &lt;em&gt;(&lt;%= @minimum_password_length %&gt; characters minimum)&lt;/em&gt;
            &lt;% end %&gt;&lt;br /&gt;
            &lt;%= f.password_field :password, autocomplete: "off", class: "form-control" %&gt;
          &lt;/div&gt;
  
          &lt;div class="field form-group"&gt;
            &lt;%= f.label :password_confirmation %&gt;&lt;br /&gt;
            &lt;%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %&gt;
          &lt;/div&gt;
  
          &lt;div class="actions form-group"&gt;
            &lt;%= f.submit "Sign up", class: "btn btn-info" %&gt;
          &lt;/div&gt;
        &lt;% end %&gt;
  </code></pre>
  
  <p>routes.rb</p>
  
  <pre><code>Rails.application.routes.draw do
    devise_for :users, controllers: { registrations: 'users/registrations' }
  
    root 'pages#home'
  </code></pre>
  
  <p>/config/application.yml</p>
  
  <pre><code>stripe_api_key: sk_test_bCKoKAs1o2jciSJ6Egi4i5tr
  stripe_publishable_key: pk_test_q8xRzIcHxx2NXmAhb2yxKxv5
  #
  # production:
  stripe_api_key: sk_test_bCKoKAs1o2jciSJ6Egi4i5tr
  stripe_publishable_key: pk_test_q8xRzIcHxx2NXmAhb2yxKxv5
  </code></pre>
  
  <hr>
  
  <ul>
  <li>edit *</li>
  </ul>
  
  <p>application_controller.rb</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    # Prevent CSRF attacks by raising an exception.
    # For APIs, you may want to use :null_session instead.
    protect_from_forgery with: :exception
  
    before_filter :configure_permitted_parameters, if: :devise_controller?
  
    protected
      def configure_permitted_parameters
        devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :stripe_card_token, :email, :password, :password_confirmation) }
      end
  end
  </code></pre>
  
  <p>and below is my server when trying to sign up a basic member</p>
  
  <pre><code>Started POST "/users" for 124.149.46.152 at 2015-08-21 02:39:09 +0000
  Cannot render console from 124.149.46.152! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  Processing by Users::RegistrationsController#create as HTML
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"b70CPfotJ27nM7Sz6SXs1iZzzct3gJcouickmCRgaFdF8N/tI/5XuIXgu0dXnOysifkaRIvjfGxFV6lx9UcbNA==", "user"=&gt;{"email"=&gt;"partnertest@test.com", "password"=&gt;"[FILTERED]", "password_confirmation"=&gt;"[FILTERED]"}, "commit"=&gt;"Sign up"}
     (0.1ms)  begin transaction
    User Exists (0.3ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = 'partnertest@test.com' LIMIT 1
    SQL (0.6ms)  INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["email", "partnertest@test.com"], ["encrypted_password", "$2a$10$DMHp9/uWFU/ChVX5s485deASl9T4x48YUVZ6QgJpsw2O9M.A4R6PS"], ["created_at", "2015-08-21 02:39:09.274684"], ["updated_at", "2015-08-21 02:39:09.274684"]]
     (9.5ms)  commit transaction
     (0.1ms)  begin transaction
    SQL (0.7ms)  UPDATE "users" SET "last_sign_in_at" = ?, "current_sign_in_at" = ?, "last_sign_in_ip" = ?, "current_sign_in_ip" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ?  [["last_sign_in_at", "2015-08-21 02:39:09.288182"], ["current_sign_in_at", "2015-08-21 02:39:09.288182"], ["last_sign_in_ip", "124.149.46.152"], ["current_sign_in_ip", "124.149.46.152"], ["sign_in_count", 1], ["updated_at", "2015-08-21 02:39:09.289989"], ["id", 6]]
     (11.8ms)  commit transaction
  Redirected to https://socialplayground-portal-runpixelrun.c9.io/
  Completed 302 Found in 191ms (ActiveRecord: 23.1ms)
  
  
  Started GET "/" for 124.149.46.152 at 2015-08-21 02:39:09 +0000
  Cannot render console from 124.149.46.152! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  Processing by PagesController#home as HTML
    Plan Load (0.3ms)  SELECT "plans".* FROM "plans"
    Rendered pages/home.html.erb within layouts/application (0.6ms)
    User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 6]]
  Completed 200 OK in 149ms (Views: 146.9ms | ActiveRecord: 0.6ms)
  </code></pre>
  
  <p>thanks</p>