I have a database of projects and payment_types .
In the Project model, a connection is established: has_and_belongs_to_many :payment_types In a model, the PaymentType connection is established: has_and_belongs_to_many :projects
When creating a new project, the user selects the checkboxes which payment types can be used through the check. It is not entirely clear how to save selected types of payments in the projects table.
I did the following:
fragment of the form from projects / new.html.erb:
<%= @payment_types.each do |type| %> <%= check_box_tag 'project[payment_type_ids][]', type.id %> <%= type.name %> <% end %> controllers / projects_controller.rb
class ProjectsController < ApplicationController def index end def new @project = Project.new @project.documents.build @payment_types = PaymentType.all end def create @payment_types = PaymentType.all @project = Project.create(project_params) if @project.save flash[:notice] = 'Your project successfully created.' redirect_to @project else render :new end end private def project_params params.require(:project).permit(:title, :description, :price, :skill, :location, :payment_type_ids, :anonymity, :price_category, :category_id, documents_attributes: [:attachment_uid]) end When creating an object, an error occurs:
Unpermitted parameters: payment_type_ids, attachment
Please tell me what needs to be added to the permitted parameters and how to correctly save the selected values from the checkboxes in my case.