0
현재 주문 관리를 위해 레일 기반 애플리케이션을 작업 중입니다. (레일 4.1.5 및 ActiveAdmin을)은Rails 다른 모델의 새로운 레코드
나는이 모델을 가지고 :
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)
을 사용하는 시도하고 새로운 양식을 렌더링하지만 어떤 매개 변수가없는 것입니다. 매개 변수가 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]
누구든지 의견이 있습니까?
controller do
def new
record = YourActiveRecordModel.new #or find, if you pass id
record.some_attribute = some_value
new!
end
end
해당 입력가 작성됩니다
@paulwang을 해결할 수 있었습니까? 나는 비슷한 딜레마에 직면하고있다. – neo