У меня есть 2 модели:
board.rb
class Board
has_and_belongs_to_many :posts, :autosave => true
end
post.rb
class Post
has_and_belongs_to_many :boards
end
В моих posts_controller.rb
def create
@post = current_user.posts.new(params[:post])
@post.save
end
В моих сообщениях просмотра у меня есть форма с полем collection_select:
<%= form_for(@post) do |f| %>
<%= f.submit %>
<%= f.collection_select :board_ids, Board.where(:user_id => current_user.id), :id, :name%>
<% end %>
Я получаю с отношением типа has_and_belongs_to_many следующая ошибка:
неопределенный метод `first 'для BSON :: ObjectId (' 4f2e61ce1d41c8412a000215 '): BSON :: ObjectId
: board_ids - это массиввведите board_ids: [] в объекте Post.
Как сохранить объект из поля collection_select в этом массиве?