ruby on rails - Argument Error First argument in form cannot contain nil or be empty -


i setting form users can add new stripe credit card. receive first argument in form cannot contain nil or empty on form <%= form_for @subscription |f| %>

what missing can have form , submitting stripe?

subscription controller:

  def new     plan = plan.find(params[:plan_id])     @subscription = plan.subscriptions.build     if params[:payerid]       @subscription.paypal_customer_token = params[:payerid]       @subscription.paypal_payment_token = params[:token]       @subscription.email = @subscription.paypal.checkout_details.email     end   end    def create     @subscription = subscription.new(params[:subscription])     if @subscription.save_with_payment       redirect_to @subscription, :notice => "thank subscribing!"     else       render :new     end   end    def show     @subscription = subscription.find(params[:id])   end    def paypal_checkout     plan = plan.find(params[:plan_id])     subscription = plan.subscriptions.build     redirect_to subscription.paypal.checkout_url(       return_url: new_subscription_url(:plan_id => plan.id),       cancel_url: root_url     )   end      def updatesubscription       @user = current_user       @customer = stripe::customer.retrieve(@user.subscription.stripe_customer_token)       @customer.update_subscription(:plan => "1", :prorate => true)      current_user.save!       flash.alert = 'your subscription has been updated!'       redirect_to root_url      end       def cancelsubscription        @user = current_user          @customer = stripe::customer.retrieve(@user.subscription.stripe_customer_token)          @customer.cancel_subscription()          current_user.save!          flash.alert = 'your subscription has been cancelled successfully!'          redirect_to root_url        end         def create_card_stripe            @user = current_user            @customer = stripe::customer.retrieve(@user.subscription.stripe_customer_token)             @customer.cards.create({              :card => @user.subscription.stripe_customer_token            })             @user.update_attribute(:stripe_card_id, customer.active_card.id)            if customer.save              flash.alert = "credit card updated successfully!"              redirect_to root_url            else              flash.alert = "error updating card"              redirect_to root_url            end          end end 

form:

add new credit card <%= form_for @subscription |f| %>   <% if @subscription.errors.any? %>     <div class="error_messages">       <h2><%= pluralize(@subscription.errors.count, "error") %> prohibited subscription being saved:</h2>       <ul>       <% @subscription.errors.full_messages.each |msg| %>         <li><%= msg %></li>       <% end %>       </ul>     </div>   <% end %>    <%= f.hidden_field :plan_id %>   <%= f.hidden_field :stripe_card_token %>    <div class="field">     <%= radio_button_tag :pay_with, :card, true %>     <%= label_tag :pay_with_card %>       <%= image_tag "visa.png" %>       <%= image_tag "mastercard.png" %>       <%= image_tag "discover.png" %>       <%= image_tag "american_express.png" %>       <%= image_tag "jcb.png" %>   </div>   <% end %>    <div id="billing_fields">     <div class="field">       <%= f.hidden_field :user_id, :value => current_user.id %>        <%= f.label :email %>       <%= f.text_field :email %>     </div>     <% if @subscription.payment_provided? %>       payment has been provided. click "subscribe" complete subscription.     <% else %>       <div class="field">         <%= label_tag :card_number, "credit card number" %>         <%= text_field_tag :card_number, nil, name: nil %>       </div>       <div class="field">         <%= label_tag :card_code, "security code on card (cvv)" %>         <%= text_field_tag :card_code, nil, name: nil %>       </div>       <div class="field">         <%= label_tag :card_month, "card expiration" %>         <%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %>         <%= select_year nil, {start_year: date.today.year, end_year: date.today.year+15}, {name: nil, id: "card_year"} %>       </div>     <% end %>     <div id="stripe_error">       <noscript>javascript not enabled , required form. first enable in web browser settings.</noscript>     </div>     <div class="actions">       <%= f.submit "new card" %>     </div>   </div> <% end %> 

you getting error because @subscription nil.

set value of @subscription in subscription controller's action renders view.


Comments