在Rails 4中我想在设计卖家中创建一个包含产品的订单,我使用gem"cocoon"
class Seller < ActiveRecord::Base
has_many :orders
class Order < ActiveRecord::Base
belongs_to :seller
has_many :products
accepts_nested_attributes_for :products, allow_destroy: true
class Product < ActiveRecord::Base
belongs_to :order
Run Code Online (Sandbox Code Playgroud)
我想在new.html中创建,但卖家不需要登录,我希望它可以通过URL
new.html
<%- model_class = Order -%>
<%= simple_form_for @order, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.simple_fields_for :products do |product| %>
<%= render 'product_fields', :f => product %>
<% end %>
<%= link_to_add_association 'add product', f, :products %>
<%= f.button :submit, :class => 'btn-primary' %>
<% end %>
in …Run Code Online (Sandbox Code Playgroud)