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?
Turns out this had to do with a the relationship needing to know of a product_type value, as product is a parent of many product types.
No way anybody here at SO would have gotten that and the Rails error didn't point in the right direction.
If somebody knows how I might have debugged that maybe a way to output all the required fields a relationship is expecting, I'll give you the points.