I have a Ruby on Rails application with some generated scaffold. Now, in one of them I need to add a parameter that wasn't planned initially.
The situation is that I have two objects: Block and Keywords. The relationship between them is has_and_belongs_to_many
. That allows me to have many keywords associated to many blocks and vice versa.
I want to add the option to add some keywords to the object Block during the creation.
I added the following code in the /views/blocks/_form.html.erb
file:
<div class="field">
<%= f.label :keywords %><br>
<%= f.collection_select(:keywords, @keywords.order(:name), :id, :name, {include_blank: true}, {:multiple => true}) %>
</div>
I added the parameter in the controller as well:
def block_params
params.require(:block).permit(:name, :title, :description, :price, :instagram, :image, :main, :action, :keywords, :block_type_id, :module_keyword_id, :playlist_id)
end
Nevertheless I get this message in the log
Unpermitted parameter: keywords
and the keywords are not added to the block. What am I missing?