我很努力,看看有什麼我做錯了這裏..態關聯未定義的方法`build_product」
我有需要能夠舉行一個產品的訂單模式,產品必須是多態的。
我有一個名爲orthosis_specification的產品/模型,出於某種原因,我在創建fields_for的過程中遇到此錯誤。
遷移 -
class CreateOrders < ActiveRecord::Migration
def change
create_table :orders do |t|
t.datetime :order_date
t.datetime :date_required
t.boolean :correct
t.references :user, index: true, foreign_key: true
t.references :practitioner, index: true, foreign_key: true
t.references :product, polymorphic: true
t.references :shipping_address, index: true, foreign_key: true
t.references :invoice_address, index: true, foreign_key: true
t.timestamps null: false
end
end
end
訂單控制器 -
def new
@order = Order.new
@order.build_patient
@order.build_product #Also tried: @order.build_orthosis_specification
end
階模型 -
class Order < ActiveRecord::Base
has_one :patient
belongs_to :product, polymorphic: true
accepts_nested_attributes_for :patient,
reject_if: proc { |attributes| attributes['first_name'].blank? },
allow_destroy: true
accepts_nested_attributes_for :product,
reject_if: proc { |attributes| attributes['transfer_name'].blank? },
allow_destroy: true
def to_s
name
end
end
矯形器規格型號 -
class OrthosisSpecification < ActiveRecord::Base
has_one :order, :as => :product, class_name: 'Order'
end
順序查看 -
<%= form_for(@order) do |f| %>
<% if @order.errors.any? %>
<% end %>
<%= f.fields_for :orthosis_specification do |fa| %>
實際的錯誤信息 -
undefined method `build_orthosis_specification' for #<Order:0x007f8950e29970>
矯形器規格遷移 -
class CreateOrthosisSpecifications < ActiveRecord::Migration
def change
create_table :orthosis_specifications do |t|
t.string :transfer_name
t.string :modifications
t.string :primary_mods
t.string :top_opening
t.string :side_opening
t.string :chape_position
t.string :scan_file
end
end
end
任何幫助,將大規模感激,謝謝!
什麼是你的錯誤是什麼呢?你能否用錯誤信息更新你的問題? – Caillou
當然,已經完成了。 – AndrewJL
您能否爲矯形器規格表添加移植?我想我有你的問題,但我想確定。 – Caillou