Skip to content

Instantly share code, notes, and snippets.

@advorak
Forked from RemiBa/ERROR
Last active December 10, 2015 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save advorak/4398014 to your computer and use it in GitHub Desktop.
Save advorak/4398014 to your computer and use it in GitHub Desktop.
NoMethodError in OrderitemsController#create
undefined method `stringify_keys' for #<Order:0x2c630a0>
Application Trace | Framework Trace | Full Trace
app/controllers/orderitems_controller.rb:11:in `create'
class Order < ActiveRecord::Base
attr_accessible :id, :title, :current_order, :customer_id, :final_pdf_created, :order_sent_at
## ASSOCIATIONS
has_many :orderitems
has_many :products, :through => :orderitems
belongs_to :customer
## METHODS
def self.defaultBoM(customer)
defaultBoM = customer.orders.new()
#defaultBoM.id = 0
defaultBoM.title = "No title"
defaultBoM.current_order = 1
defaultBoM.final_pdf_created = 0
defaultBoM.created_at = defaultBoM.updated_at = DateTime.now()
defaultBoM
end
end
def create
customer = Customer.find(session[:customer_id]) if session[:customer_id]
if customer
#If order ID = 0 --> This has to be a new order, it hasn't been made yet
if params[:order_id] # params[:order_id] will return nil if the value doesn't exist in the submitted form...
#Get the default order
order = Order.defaultBoM(customer)
#order.id = nil # order.id will default to nil with a new record
#Create it
#order = Order.create(order)
order.save # this saves the order, which is contained within the order object
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment