I'm trying to create a relationship between two models in rails.
I have a Product and an Offer where an Offer belongs to a Product.
class Product
include Mongoid::Document
include Mongoid::Timestamps
has_many :offers, as: :trigger_product, :class_name => "Offer"
end
class Offer
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :trigger_product, polymorphic: true
accepts_nested_attributes_for :images, :product
end
in formtastic, the field for the trigger product is added as so
<%= f.input :trigger_product, :as=> :select, :multiple => false, :collection => @offer.trigger_products_list %>
when I submit the form, I get an error
NameError in Admin::OffersController#create uninitialized constant TriggerProduct app/controllers/admin/Offers_controller.rb:7:in `create'
It appears to me the polymorphic association isn't working, I don't think I should need to create an empty model to hold the TriggerProduct, but the error leads me to believe this is the issue.
Any suggestions here?