ruby on rails - How to show select menu for two models? -
i'm using simple form , don't how show values of 2 associations.
a price can belong service or product not both @ same time.
price # service_id, product_id belongs_to :services # service.name belongs_to :products # product.name end
instead having simple form this:
<%= f.association :product, :input_html => { :class => "span5 } %> <%= f.association :service, :input_html => { :class => "span5 } %>
i want turn 1 field instead.
what way simple_form_for
?
what regular form_for
?
i think better way use polymorphic association.
class price belongs_to :pricable, polymorphic: true end class product has_one :price, as: :priceable end class service has_one :price, as: :priceable end
then, in form, can use:
<%= form_for [@priceable, price.new]
where @priceable product or service.
Comments
Post a Comment