Хочу сделать вполне обычную вещь: создать мульти-модельную форму. Почему-то на странице создания item не появляется поле collection.
class Item
include MongoMapper::AcceptsNestedAttributes
include Mongoid::Document
include Mongoid::Timestamps
has_many :statuses, dependent: :delete, autosave: true
has_one :collection
field :name, type: String
field :description, type: String
field :cost, type: BigDecimal
accepts_nested_attributes_for :collection, autosave: true
end
class Collection
include Mongoid::Document
belongs_to :item
field :name, type: String
end
def new
@item = Item.new
end
def create
@item = Item.new(item_params)
respond_to do |format|
if @item.save
format.html { redirect_to @item, notice: 'Item was successfully created.' }
format.json { render :show, status: :created, location: @item }
else
format.html { render :new }
format.json { render json: @item.errors, status: :unprocessable_entity }
end
end
end
= form_for @item do |f|
.field
= f.label :name
br
= f.text_field :name, class: "form-control"
.field
= f.label :description
br
= f.text_area :description, class: "form-control"
.field
= f.label :cost
br
= f.number_field :cost
.field
= f.fields_for :collection do |builder|
= builder.label :collection, "Collection"
= builder.text_field :name, collection: ['Car', 'Truck']
.actions = f.submit