问题
I tried setting up a waaaaaaay too complex order form (How to set up a order form with options belonging to a product_category)
Therefore, I am trying to take it slow and split up my order form, where:
- first an
product_category
is selected and - if the
product_category
is available, the user can select the product andoptions
belonging to theproduct_category
.
Is there a way to do this with a multi-step form http://railscasts.com/episodes/217-multistep-forms? Or are there easier methods to create forms based on input?
Code
models
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
来源:https://stackoverflow.com/questions/58800066/easiest-way-to-design-a-form-where-displayed-form-options-are-dependent-on-inpu