title: Add Record to Existing Collection in a Rails App
body: <p>I am attempting to develop a model in which a user can add the recipe they are viewing to an existing menu of recipes they have created, similar to adding a song to a custom playlist. I believe I have the models set up correctly (using a many to many through relationship) however I am unsure how to go about the adding of the actual records to a selected collection. Any guidance would be helpful. My code is as below.</p>
  
  <p>Menus Controller</p>
  
  <pre><code>class MenusController &lt; ApplicationController
  before_action :set_search
  
  def show
      @menu = Menu.find(params[:id])
  end
  
  def new
      @menu = Menu.new
  end
  
  def edit
      @menu = Menu.find(params[:id])
  end
  
  def create
      @menu = current_user.menus.new(menu_params)
  
      if @menu.save
          redirect_to @menu
      else
          render 'new'
      end
  end
  
  def update
      @menu = Menu.find(params[:id])
  
      if @menu.update(menu_params)
          redirect_to @menu
      else
          render 'edit'
      end
  end
  
  def destroy
      @menu = Menu.find(params[:id])
      @menu.destroy
  
      redirect_to recipes_path
  end
  
  private
  def menu_params
      params.require(:menu).permit(:title)
  end
  end
  </code></pre>
  
  <p>Menu Model</p>
  
  <pre><code>class Menu &lt; ApplicationRecord
  belongs_to :user
  has_many :menu_recipes
  has_many :recipes, through: :menu_recipes
  end
  </code></pre>
  
  <p>menu_recipe Model</p>
  
  <pre><code>class MenuRecipe &lt; ApplicationRecord
    belongs_to :menu
    belongs_to :recipe
  end
  </code></pre>
  
  <p>Recipe Model</p>
  
  <pre><code>class Recipe &lt; ApplicationRecord
  belongs_to :user
  has_one_attached :cover
  
  has_many :menu_recipes
  has_many :menus, through: :menu_recipes
  
  
  end
  </code></pre>
  
  <p>User Model</p>
  
  <pre><code>class User &lt; ApplicationRecord
  has_secure_password
  has_one_attached :profile_image
  has_many :recipes
  has_many :menus
  end
  </code></pre>