Я использую Ruby on Rails 5.2.3 и Mongoid
Я пытаюсь добавить несколько категорий.
category.rb
class Category
include Mongoid::Document
has_many :tickets
belongs_to :user
end
ticket.rb
class Ticket
include Mongoid::Document
belongs_to :user
belongs_to :category, touch: true
end
tickets / _form.html.erb
<%= form_for(@ticket, html: { role: 'form' }) do |f| %>
<%= f.collection_select :category_id, Category.all, :id, :title, options = { include_hidden: false }, html_options = { multiple: true } %>
<%= f.submit 'Save' %>
<% end %>
При попытке сохранить выдает ошибку, что «Категория не может быть пустой»
log
Обработка TicketsController # создать в виде HTML-параметров: {"utf8" => "✓", "authenticity_token" => "rZyRkTPqTdM // ymnKGsm4Ctm5Co7YgAnSQg6oOaOVv4qEua1QB6cxlh1_hq" hh2 "hh2" h0 "h1" h1 "h0" h1 "h1" h1 "h1" h0 "h1" h2 "hg2" h1 ")" h1 "h0" h1 "h0" h1 "h0" h1 "h2" hg2 "h1" h0 "h1" h0 "h1" h0 "h1" h0 "h0" h1 "h0" h0 "h1" h1 "h0" h1 "h1" h0 "h1" h1 "h0" h0 "h1" h0 "h1" h1 "h0" h1 "h1" h0 "h1" h0 "hg2" h1h2 "h0") "h0"=> "test", "description" => "test", "category_id" => ["5d0939d51996da62c1bd4699", "5d0939de1996da62c1bd469a"]}, "commit" => "Save"} MONGODB |localhost: 27017 |remotely_development.find |НАЧАЛО |{"find" => "users", "filter" => {"_ id" => BSON :: ObjectId ('5d77b34d1996da1a261c111d')}, "sort" => {"_ id" => 1}, "limit" => 1, "singleBatch" => true, "lsid" => {"id" =>}} MONGODB |localhost: 27017 |remotely_development.find |УСПЕШНО |0,002 с MONGODB |localhost: 27017 |remotely_development.find |НАЧАЛО |{"find" => "category", "filter" => {"_ id" => [BSON :: ObjectId ('5d0939d51996da62c1bd4699'), BSON :: ObjectId ('5d0939de1996da62c1bd469a')]}, "limit" => 1, "singleBatch" => true, "lsid" => {"id" =>}} MONGODB |localhost: 27017 |remotely_development.find |УСПЕШНО |0.003s Рендеринг билетов / new.html.erb в макетах / приложении. Предоставление общего доступа / _error_messages.html.erb (0.9ms) MONGODB |localhost: 27017 |remotely_development.find |НАЧАЛО |{"find" => "category", "filter" => {}, "lsid" => {"id" =>}} MONGODB |localhost: 27017 |remotely_development.find |УСПЕШНО |0,001s Отрендеренные тикеты / _form.html.erb (9,7 мс) Отрисованные тикеты / new.html.erb в макетах / приложении (12,9 мс)104,9мс | MongoDB: 0,0мс)