title: NoMethodError undefined method `id' for nil:NilClass:
body: <p>I know this kind of question is already answered multiple times but i seriously unable to figure it out what is causing a problem here, I am having trouble solving this problem. I keep getting the same error when i'm trying to create new registration ( <a href="http://localhost:3000/registrations/new?course_id=1" rel="nofollow">http://localhost:3000/registrations/new?course_id=1</a> ) :</p>
  
  <pre><code>NoMethodError at /registrations
  
  undefined method `id' for nil:NilClass
  </code></pre>
  
  <p>Here is my RegistrationsController: </p>
  
  <pre><code>class RegistrationsController &lt; ApplicationController
    before_action :set_registration, only: [:show, :edit, :update, :destroy]
  
    def index
      @registrations = Registration.all
    end
  
    def show
    end
  
    def new
      @registration = Registration.new
      @course = Course.new
      @course = Course.find_by id: params["course_id"]
    end
  
    def create
      @registration = Registration.new registration_params.merge(email: stripe_params["stripeEmail"], card_token: stripe_params["stripeToken"])
      raise "Please Check Registration Errors" unless @registration.valid?
      @registration.process_payment
      @registration.save
      redirect_to @registration, notice: 'Registration was successfully created.'
    rescue Exception =&gt; e
      flash[:error] = e.message
      render :new
    end
  
    protect_from_forgery except: :webhook
    def webhook
      event = Stripe::Event.retrieve(params["id"])
  
      case event.type
        when "invoice.payment_succeeded" #renew subscription
          Registration.find_by_customer_id(event.data.object.customer).renew
      end
      render status: :ok, json: "success"
    end
  
    private
  
      def stripe_params
        params.permit :stripeEmail, :stripeToken
      end
  
      def set_registration
        @registration = Registration.find(params[:id])
      end
  
      def registration_params
        params.require(:registration).permit(:course_id, :full_name, :company, :telephone, :email, :card_token)
      end
  
  end
  </code></pre>
  
  <p>My Registration Model:</p>
  
  <pre><code>class Registration &lt; ActiveRecord::Base
    belongs_to :course
  
    def process_payment
      customer_data = {email: email, card: card_token}.merge((course.plan.blank?)? {}: {plan: course.plan})
      customer = Stripe::Customer.create customer_data
  
        Stripe::Charge.create customer: customer.id,
                              amount: course.price * 100,
                              description: course.name,
                              currency: 'usd'
        #Annotate Customer Id when Registration is Created
        cusotmer_id = customer.id
  
    end
  
    def renew
      update_attibute :end_date, Date.today + 1.month
    end
  
  end
  </code></pre>
  
  <p>Registration New.html.haml File :</p>
  
  <pre><code>%section#course-content
    %section#ruby
      %section.detailed-syllabus
        .wrapper-inside
          = form_for @registration, html: { class: "basic-grey" } do |f|
            - if @registration.errors.any?
              #error_explanation
                %h2
                  = pluralize(@registration.errors.count, "error")
                  prohibited this registration from being saved:
                %ul
                  - @registration.errors.full_messages.each do |message|
                    %li= message
            .field
              = f.hidden_field :course_id, value: @course.id
            .field
              = f.label :full_name
              = f.text_field :full_name
            .field
              = f.label :company
              = f.text_field :company
            .field
              = f.label :email
              = f.text_field :email
            .field
              = f.label :telephone
              = f.text_field :telephone
  
              //‘Stripe.js’ will recognize the card data because we have marked the inputs with ‘data-stripe’ attribute as: number, cvv, exp-month and exp-year.
              = javascript_include_tag "https://js.stripe.com/v2/"
              :javascript
                Stripe.setPublishableKey('#{Rails.application.secrets.stripe_publishable_key}');
  
              = label_tag "Card Number", nil, required: true
              .control-group
                .controls
                  = text_field_tag :card_number, nil, class: "input-block-level", "data-stripe" =&gt; "number"
  
              = label_tag "Card Verification", nil, required: true
              .control-group
                .controls
                  = text_field_tag :card_verification, nil, class: "input-block-level", "data-stripe" =&gt; "cvv"
  
              = label_tag "Card Expires", nil, required: true
              = select_tag :exp_month, options_for_select(Date::MONTHNAMES.compact.each_with_index.map { |name,i| ["#{i+1} - #{name}", i+1] }), include_blank: false, "data-stripe" =&gt; "exp-month", class: "span2"
              = select_tag :exp_year, options_for_select((Date.today.year..(Date.today.year+10)).to_a), include_blank: false, "data-stripe" =&gt; "exp-year", class: "span1"
  
  
            .actions
            = f.submit "Registration Payment", class: "btn", style: "color: white;background: rgb(242, 118, 73);"
  </code></pre>
  
  <p>Does anyone know how to assist me in this? Greatly appreciate all the help.
  Additional Can anyone please guide me through how to pass id between 2 models like this guy did between 2 models as he's creating a scaffold for one model but passing ID lets him create values for another model too without creating actions for another controller <a href="https://github.com/gotealeaf/stripe-basics.git" rel="nofollow">https://github.com/gotealeaf/stripe-basics.git</a></p>
  
  <p>Edited:
  GitHub Repository For This Code
  <a href="https://github.com/ChiragArya/Stripe_CheckOut_Demo" rel="nofollow">https://github.com/ChiragArya/Stripe_CheckOut_Demo</a></p>