Searched through all other same questions, nothing worked. I have User, which can create Track, but can also learn other Tracks. Learning other Tracks is saved in track_users.
model User.rb:
# has track as author!
has_many :tracks
# has track as student!
has_many :tracks_users
has_many :courses, through: :tracks_users, source: :track
accepts_nested_attributes_for :tracks_users
model Track.rb
# has coach!
belongs_to :user
# has students!
has_many :tracks_users
has_many :students, through: :tracks_users, source: :user
accepts_nested_attributes_for :tracks_users
and model TracksUser.rb:
attr_accessible :track_id, :user_id, :as => [:default, :admin]
belongs_to :track
belongs_to :user
accepts_nested_attributes_for :track
and in my tracks/_follow.html.erb:
<%= form_for(current_user.courses.build(track_id: @track)) do |f| %>
<div><%= f.hidden_field :track_id %></div>
<%= f.submit "Take track", class: "btn btn-large btn-primary" %>
<% end %>
And this throws "Can't mass-assign protected attributes: track_id". I even set config.active_record.whitelist_attributes = false - doesn't work.
There is separate configuration option, explicitly for development stage - in config/environments/development.rb:
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
Error is gone by outcommenting that.
I have not seen this configuration mentioned anywhere in StackOverflow. Found it on http://net.tutsplus.com/tutorials/ruby/mass-assignment-rails-and-you/, so thanks tutsplus.