This was difficult due to [], which are needed to work with flag collections. Just follow these steps:
View:
<% @books.each do |b| %>
<%= check_box_tag "books[#{b.id}]", b.book %>
<%= label_tag "books[#{b.id}]", b.book %>
<br />
<% end %>
Then in the controller access to the parameter will be values. Otherwise, it looks like 135 => Book1. Use valuesto get only Book1
PARAMS [: books] .values
- check_box_tag <label> :
...
<label><%= check_box_tag "books[]", b.book %></label>
...
, #{b.id},
params[:books]