title: Add additional parameters from form into join table - has_many through
body: <p>My problem is that I have a has_many through relationship between workers and trainings and a special join table that contains additional information about  trainings each worker has done.</p>
  
  <h3>training.rb</h3>
  
  <pre><code>class Training &lt; ApplicationRecord
    belongs_to :worker, optional: true
    belongs_to :line, optional: true
    has_many :trainingslines
    has_many :trainingsmemberships
    has_many :workers, through: :trainingsmemberships
    has_many :lines, through: :trainingslines
    accepts_nested_attributes_for :worker
    accepts_nested_attributes_for :line
    accepts_nested_attributes_for :trainingsmemberships
    validates :name, presence: true, length: { minimum: 1 }
    mount_uploader :attachement
  end
  </code></pre>
  
  <h3>trainings_controller.rb</h3>
  
  <pre><code>class TrainingsController &lt; ApplicationController
    before_action :logged_in_user
    before_action :admin_user
    helper_method :sort_column, :sort_direction
  
    def index
      @trainings = Training.paginate(page: params[:page])
    end
  
    def new
      @training = Training.new
    end
  
    def show
      @training = Training.find(params[:id])
    end
  
    def insert_line(line)
      self.line.clear
      self.line &lt;&lt; line
    end
  
    def insert_worker(worker)
      self.worker.clear
      self.worker &lt;&lt; worker
    end
  
    def create
      @training = Training.new(training_params)
      if @training.save
        flash[:info] = "Training hinzugefügt."
        redirect_to root_url
      else
        render 'new'
      end
    end
  
    def destroy
      Training.find(params[:id]).destroy
      flash[:success] = "Training gelöscht"
      redirect_to trainings_url
    end
  
    def edit
      @training = Training.find(params[:id])
    end
  
    def update
      @training = Training.find(params[:id])
      if @training.update_attributes(training_params)
        flash[:success] = "Training updated"
        redirect_to training_path
      else
        render 'edit'
      end
    end
  
    def add_worker_tm
      @workers = Worker.order("#{sort_column} #{sort_direction}")
    end
  
    def addworkers_tm
      @trainings = Training.all
      @training = params[:training_id]
      @tm = Trainingsmembership.new(tm_params)
      if @tm.save
        flash[:success] = "Mitarbeiter eingefügt"
        redirect_to training_path
      else
        render 'add_worker_tm'
      end
    end
  
  
    private
    def sortable_columns
      ["name", "line_ids", "shift_id", "position_id"]
    end
  
    def sort_column
      Worker.column_names.include?(params[:sort]) ? params[:sort] : "name"
    end
  
    def sort_direction
      %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
    end
  
    def training_params
      params.require(:training).permit(:name, :shortname, :clockcycle, :cc, :jcms, :status, :line_ids =&gt; [], :worker_ids =&gt; [])
    end
  
    def tm_params
      params.require(:trainingsmembership).permit(:worker_id, :training_id, :duration, :date, :attachement, :comment)
    end
  
    # Confirms a logged-in user.
    def logged_in_user
      unless logged_in?
        store_location
        flash[:danger] = "Please log in."
        redirect_to login_url
      end
    end
  
    # Confirms an admin user.
    def admin_user
      redirect_to(root_url) unless current_user.admin?
    end
  end
  </code></pre>
  
  <h3>add_worker_tm.html.erb</h3>
  
  <pre><code>&lt;%= simple_form_for(@trainingmem = Trainingsmembership.new, url: add_worker_tm_trainings_path) do |f| %&gt;
        &lt;%= f.input :training_id, collection: Training.all, label_method: :name, value_method: :id, label: 'Training:', include_blank: false %&gt;
        &lt;%= f.input :duration, label: 'Gültigkeit:' %&gt;
        &lt;%= f.input :date, :as =&gt; :string, :input_html =&gt; { data: {behaviour: "datepicker"}}, label: 'Prüfungstermin:' %&gt;
        &lt;%= f.input :worker_id, collection: Worker.all, label_method: :name, value_method: :id, label: 'Mitarbeiter', include_blank: false, input_html: { multiple: true } %&gt;
        &lt;%= f.input :comment, as: :text, label: 'Bemerkung:' %&gt;
        &lt;%= f.input :attachement, as: :file, label: 'PDF-Protokoll:' %&gt;
        &lt;%= f.submit "Edit training", class: "btn btn-primary" %&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <h3>trainingsmembership.rb</h3>
  
  <pre><code>class Trainingsmembership &lt; ApplicationRecord
        belongs_to :worker
        belongs_to :training
      end
  </code></pre>
  
  <p>My trainingsmembership table has the following columns:</p>
  
  <pre><code>create_table :trainingsmemberships, id: false do |t|
        t.belongs_to :worker, index: true
        t.belongs_to :training, index: true
        t.integer :duration
        t.timestamp :date
        t.string :attachement
        t.text :comment
        t.timestamps
      end
  </code></pre>
  
  <p>I want to use my trainings controller with this simple_form to add a worker with all additional parameters into the trainingsmembership table.</p>
  
  <p>I am quite new to ruby on rails and made some others has many through relationships working but all of them are without any additional data in the join tables. Or do I need a new trainingsmembership controller?</p>
  
  <p>I have already googled but I have not found any usefull advice.</p>
  
  <p>Edit: Currently I am getting no error message, I just will be redirected to the same page. My debuger gives this information:</p>
  
  <pre><code>Started POST "/trainings/add_worker_tm" for 127.0.0.1 at 2018-08-20 15:32:44 +0200
  Processing by TrainingsController#addworkers_tm as HTML
    Parameters: {"utf8"=&gt;"âœ“", "authenticity_token"=&gt;"bZ0MxPcFgUe0EvoVd6VSeUWm4ZT5y0fc8A+eYZmuvvCLh8VoV0e63pxKTKSmvkUuNx1WUMB70Av6uahnt6Av/A==", "trainingsmembership"=&gt;{"training_id"=&gt;"1", "duration"=&gt;"12", "date"=&gt;"21.08.2018", "worker_id"=&gt;["", "1"], "comment"=&gt;""}, "commit"=&gt;"Training bearbeiten"}
    User Load (1.0ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
    â†³ app/helpers/sessions_helper.rb:22
  Unpermitted parameter: :worker_id
     (1.0ms)  BEGIN
    â†³ app/controllers/trainings_controller.rb:72
    Training Load (0.0ms)  SELECT  `trainings`.* FROM `trainings` WHERE `trainings`.`id` = 1 LIMIT 1
    â†³ app/controllers/trainings_controller.rb:72
     (0.0ms)  ROLLBACK
    â†³ app/controllers/trainings_controller.rb:72
    Rendering trainings/add_worker_tm.html.erb within layouts/application
    Training Load (1.0ms)  SELECT `trainings`.* FROM `trainings`
    â†³ app/views/trainings/add_worker_tm.html.erb:54
    Worker Load (1.0ms)  SELECT `workers`.* FROM `workers`
    â†³ app/views/trainings/add_worker_tm.html.erb:57
    Rendered trainings/add_worker_tm.html.erb within layouts/application (429.9ms)
    Rendered layouts/_shim.html.erb (0.0ms)
    Rendered layouts/_header.html.erb (2.0ms)
    Rendered layouts/_footer.html.erb (1.0ms)
  Completed 200 OK in 654ms (Views: 594.1ms | ActiveRecord: 3.9ms)
  </code></pre>