Ask A Question

Notifications

You’re not receiving notifications from this thread.

undefined method `minimum' for #<Store:0x00007fb25c749b20>

Samantha O asked in General

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 %>

Reply

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 %>
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.