Самый простой способ создать форму, где отображаемые параметры формы зависят от ввода - PullRequest
0 голосов
/ 11 ноября 2019

Я попытался создать слишком сложную форму заказа ( Как настроить форму заказа с опциями, относящимися к категории товаров )

Поэтому я пытаюсь сделать это медленно иразделите мою форму заказа, где:

  • сначала выбирается product_category и
  • , если доступно product_category, пользователь может выбрать продукт и принадлежащие optionsдо product_category.

Есть ли способ сделать это с помощью многошаговой формы http://railscasts.com/episodes/217-multistep-forms? Или существуют более простые способы создания форм на основе ввода?

Код

модели

class Order < ApplicationRecord
  belongs_to :store
  belongs_to :product

  has_many :order_options, dependent: :destroy
  has_many :options, through: :order_options
  accepts_nested_attributes_for :order_options
end

class OrderOption < ApplicationRecord
  belongs_to :option
  belongs_to :order
  accepts_nested_attributes_for :option
end

class Option < ApplicationRecord
  belongs_to :product_category
  has_many :order_options, dependent: :destroy
  has_many :orders, through: :order_options
end

class ProductCategory < ApplicationRecord
  belongs_to :store
  has_many :products, dependent: :destroy
  accepts_nested_attributes_for :products, allow_destroy: true
  has_many :options, dependent: :destroy
  accepts_nested_attributes_for :options, allow_destroy: true
end
...