title: Getting "can't write unknown attribute" when trying to save has_many association
body: <p>I”m using Rails 5.  I have two models that relate to one another …</p>
  
  <pre><code>class Scenario &lt; ApplicationRecord
    belongs_to :grading_rubric, optional: true
    has_many :confidential_memo
    has_many :roles
  
    attr_accessor :roles_str
  end 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Role &lt; ApplicationRecord
    belongs_to :scenario
  end
  </code></pre>
  
  <p>I have this table that relates the two …</p>
  
  <pre><code>sims=&gt; \d scenario_roles
                                    Table "public.scenario_roles"
     Column    |            Type             |                          Modifiers                          
  -------------+-----------------------------+-------------------------------------------------------------
   id          | integer                     | not null default nextval('scenario_roles_id_seq'::regclass)
   scenario_id | integer                     | 
   role_id     | integer                     | 
   created_at  | timestamp without time zone | not null
   updated_at  | timestamp without time zone | not null
  </code></pre>
  
  <p>However, when I try and create and save things in my controller, I’m having a problem.  Here’s what I’m doing</p>
  
  <pre><code>  def create
      @scenario = Scenario.new(scenario_params)
      # Define the roles for this scenario
      role_names = @scenario.roles_str.split("\n")
      roles = []
      role_names.each do |role|
        role_obj = Role.new({:name =&gt; role, :scenario =&gt; @scenario})
        if role_obj.save!
          roles.push(role_obj)
        end
      end
      @scenario.roles = roles
      respond_to do |format|
        if @scenario.save
  </code></pre>
  
  <p>I’m getting the error, “can't write unknown attribute <code>scenario_id</code>” on the line “role_obj = Role.new({:name => role, :scenario => @scenario})”.  What am I doing wrong?</p>