0
我目前正在開發基於軌道的應用程序來管理訂單。 (Rails的4.1.5和ActiveAdmin)來自不同型號的Rails 4新記錄
我有這些模型:
class Customer < ActiveRecord::Base
has_many :estimates
has_many :orders
accepts_nested_attributes_for :estimates, :allow_destroy => true
accepts_nested_attributes_for :orders, :allow_destroy => true
end
class Order < ActiveRecord::Base
belongs_to :customer
has_many :line_items, as: :cartable
accepts_nested_attributes_for :line_items, :allow_destroy => true
end
class Estimate < ActiveRecord::Base
belongs_to :customer
has_many :line_items, as: :cartable
accepts_nested_attributes_for :line_items, :allow_destroy => true
end
我想要做的是創建基於估算紀錄新秩序。該事情的工作,如果我創建一個新的訂單,並顯示在編輯頁面:
member_action :confirm, :method => :get do
old_estimate = Estimate.find(params[:id])
new_estimate = Order.create(old_estimate.attributes.merge({:id => nil, :created_at =>
nil,:updated_at => nil}))
old_estimate.line_items.each do |li|
new_estimate.line_items.create(li.attributes.merge({:id => nil, :created_at => nil,
:updated_at => nil}))
end
redirect_to edit_customer_order_path(new_estimate.customer, new_estimate)
end
,但我想用「新」行動,創建後,才進行了編輯,並確認記錄。
我試圖用
redirect_to new_customer_order_path(old_estimate.customer, old_estimate.attributes)
,它會呈現新的形式,但沒有任何參數。 PARAMS在URL中,但我在日誌中收到了「未經許可的參數:」。所有參數允許在Active Admin下(或者在other.rb和estimate.rb下):
permit_params :id, :customer_id, :title, :edd, :total,
line_items_attributes: [:id, :cartable_id, :cartable_type, :product_type, :source_lang, :dest_lang, :unit_price, :total, :_destroy]
任何人有任何建議嗎?
你能解決這個@paulwang嗎?我面臨着類似的困境。 – neo 2016-03-10 17:41:22