title: Rails keeps showing "UnkownAttributeError" while trying to insert into two tables from one controller
body: <p>What I wanted to do is get the </p>
  
  <blockquote>
    <p>last_insert_id</p>
  </blockquote>
  
  <p>of a table and insert it into another table but I get this error while doing it this way(I don't know if this is the right way to do such things) </p>
  
  <blockquote>
    <p>ActiveModel::UnknownAttributeError (unknown attribute 'content' for MessagePicture.): # This is copied from the console
    unknown attribute 'content' for MessagePicture. # Copied from the Browser and it had this number highlighted</p>
    
    <p>@message = current_user.messages.build.message_pictures.build(message_params)</p>
  </blockquote>
  
  <p>This is the </p>
  
  <blockquote>
    <p>new and create methods of the Message_controller class</p>
  </blockquote>
  
  <pre><code>def new
      @message = current_user.messages.build if logged_in?
      @reciever = User.find_by(params[:id])
    end
  
  
  
  def create
      #@msg = Message.new(user_params)
      @message = current_user.messages.build.message_pictures.build(message_params)
  
      if @message.save
        if @message[:picture].present?
          # Send this to the message model for insertion with the @message_id and from the picture model, insert it to the
          add_msg_pic(msg = [@message.id,@message[:msg_img_url]])
        end
  
        flash[:success] = "Message sent"
        redirect_to messages_path
      else
        flash.now[:danger] = "Message not sent"
        render 'new'
      end
    end
  </code></pre>
  
  <p>This is the </p>
  
  <blockquote>
    <p>message_params method</p>
  </blockquote>
  
  <pre><code>def message_params
    params.require(:message).permit(:content, :receiver, :sender, :archive, message_pictures_attributes:[:msg_img_url, :message_id])
  end
  </code></pre>
  
  <p>This is the </p>
  
  <blockquote>
    <p>Message class(model) add_msg_pic method</p>
  </blockquote>
  
  <pre><code>def add_msg_pic(msg)
      msg.message_pictures.each.do |m|
      m.message.id = nil
      message_pictures &lt;&lt; m
  end
  
  This is the view page
  &lt;h1&gt;Compose a new message&lt;/h1&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-md-6 col-md-offset-3"&gt;
          &lt;%= form_for(@message, html: { multipart: true }) do |f| %&gt;
  
            &lt;%= render 'shared/error_messages', object: @message %&gt;
  
            &lt;%= f.label :content %&gt;
            &lt;%= f.hidden_field :receiver, value: @reciever %&gt;
            &lt;%= f.hidden_field :sender, value: current_user.id %&gt;
            &lt;%= f.text_area :content, size:"20x15" %&gt;
            &lt;%= f.submit "Send message", class: "btn btn-primary" %&gt; 
  
            &lt;span class="picture"&gt;
              &lt;%= f.fields_for :message_pictures do |mp| %&gt;
                &lt;%= mp.file_field :msg_img_url, accept: 'image/jpeg,image/gif,image/png' %&gt;
              &lt;% end %&gt;   
            &lt;/span&gt;
          &lt;% end %&gt;
          &lt;%= button_to "Save message", archive_messages_path %&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>