10

undefined local variable or `current_order '

 2 years ago
source link: https://www.codesd.com/item/undefined-local-variable-or-current-order.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

undefined local variable or `current_order '

advertisements

I created a new model named PaypalOrder using:

rails generate model order_id:integer ip_address:string first_name:string last_name:string card_type:string card_expires_on:date

Then I ran rake db:migrate

Now my order model looks like:

class PaypalOrder < ActiveRecord::Base
  belongs_to :order

  attr_accessor :card_number, :card_verification

  validate :validate_card, :on => :create

  def purchase
  #code
  end

  private
  def validate_card
  #code
  end

  def credit_card
  #code
  end

end

and the controller i created:

class PaypalOrdersController < ApplicationController

  def new
    @paypal_order = PaypalOrder.new
  end

  def create
    @paypal_order = current_order.build_paypal_order(params[:paypal_order])
    if @paypal_order.save
      # ...
    else
      render :action => "new"
    end
  end
end

But I'm getting the following error:

NameError in PaypalOrdersController#create

undefined local variable or method `current_order' for #<PaypalOrdersController:0xf7b0a34>

Why am I not able to access the current_order and how can I successfully build paypal_order

EDIT: made the following change:

class PaypalOrdersController < Spree::BaseController

works fine now!!


Why not change line 8 of your controller to:

@paypal_order = PaypalOrder.new(params[:paypal_order])

If it is Rails 4 you'll have to do:

@paypal_order = PaypalOrder.new(params.require(:paypal_order).permit!)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK