undefined method `minimum' for #<Store:0x00007fb25c749b20>
Hi,
I have a Store model and a PricingClassification model. The PricingClassification belongs to Store. I have made a wizard for creating a store and I am trying to add a range in pricingClassification. But I get the undefined method `minimum' for #Store:0x00007fb25c749b20
What am I missing or doing wrong?
class Store < ApplicationRecord
has_many :pricing_classifications, dependent: :destroy
end
class PricingClassification < ApplicationRecord
belongs_to :store
end
module PricingClassificationsHelper
def range_string(pricing_classification)
"#{pricing_classification.minimum}-#{pricing_classification.maximum}"
end
end
While creating a new store I have this in my view.
<%= f.label :pricing_classification %>
<%= select_tag nil, options_for_select(range_options, range_string(f.object)) %>
<%= f.hidden_field :minimum %>
<%= f.hidden_field :maximum %>
It works!
I had to add a form_for block in the view and pass the pricingclassification object.
<%= form_for :pricing_classification do |f| %>
<%= f.label :pricing_classification %>
<%= select_tag nil, options_for_select(range_options, range_string(PricingClassification.new)), data: { action: "change->range#change" } %>
<%= f.hidden_field :minimum, data: { target: "range.minimum" } %>
<%= f.hidden_field :maximum, data: { target: "range.maximum" } %>
<% end %>