title: Ruby on Rails: wrong number of arguments (given 0, expected 1)
body: <p>I have an issue with my <code>add_item</code> method and have trouble to understand why.</p>
  
  <p>Here is my <code>carts_controller.rb</code></p>
  
  <pre><code>class CartsController &lt; ApplicationController
    def index
      @cart_items = CartItem.all
    end
  
    def add_item
      @cart_item = CartItem.new
      produit_id = params[:produit_id]
      @cart_item = CartItem.find_or_create_by(params[:produit][:produit_id])
      @cart_item.save
  
      binding.pry
    end
  end
  </code></pre>
  
  <p>Here is <code>produits/index.html.erb</code> (where the issue comes from)</p>
  
  <pre><code>&lt;div id="produits-column-container"&gt;
    &lt;% if @produits %&gt;
      &lt;% @produits.in_groups_of(4, false).each do |g| %&gt;
        &lt;% g.each do |produit| %&gt;
        &lt;div id="produits-row-container"&gt;
          &lt;div id="fiche-produit-container"&gt;
              &lt;div id="produit-img"&gt;
                &lt;%= image_tag produit.photo %&gt;
              &lt;/div&gt;
              &lt;div id="produit-nom"&gt;
                &lt;%= produit.nom %&gt;
              &lt;/div&gt;
              &lt;div id="produit-prix"&gt;
                &lt;%= number_to_currency(produit.prix, unit: '€', format: "%n%u") %&gt;
              &lt;/div&gt;
              &lt;div id="produit-au-panier"&gt;
                &lt;%= image_tag('icon/icon-panier') %&gt;
                &lt;%= link_to 'Ajouter au panier', carts_add_item_path, method: :post %&gt;
              &lt;/div&gt;
           &lt;/div&gt;
         &lt;/div&gt;
        &lt;% end %&gt;
      &lt;% end %&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The error i'm given is :</p>
  
  <pre><code>ArgumentError in CartsController#add_item
  wrong number of arguments (given 0, expected 1)
  
  in def add_item(produit_id)
  </code></pre>
  
  <p><code>add_item(produit_id)</code> is related to <code>carts_add_item_path</code></p>
  
  <p>I also give you the routes :</p>
  
  <pre><code>Rails.application.routes.draw do
  
    match "/mon-panier" =&gt; 'carts#index', via: :get
  
    post 'carts/add_item' =&gt; 'carts#add_item'
  
    resources :categories do
      resources :produits
    end
  
    resources :order_abonnements, only: [:create, :update, :delete]
  
    get 'livraisons_type/index'
  
    match "/recapitulatif" =&gt; 'recapitulatif#index', via: :get
  
    match "/confirmation-carte-cadeau" =&gt; 'recapitulatif#confirmation', via: :get
  
    match "/livraison-carte-cadeau" =&gt; 'livraison_carte#index', via: :get
  
    match '/activation-carte' =&gt; 'code_carte_cadeau#index', via: :get
  
    match "/offrir-une-box-bretonne" =&gt; 'cadeau#index', via: :get
  
    resources :order_items, only: [:create, :update, :destroy]
  
    match "/nos-box" =&gt; 'nos_box#index', via: :get
  
    get 'categories/index'
  
    devise_for :admin_users, ActiveAdmin::Devise.config
    ActiveAdmin.routes(self)
  
    match '/informations-penn-ar-box' =&gt; 'informations_penn_ar_box#index', via: :get
  
    match '/livraison-box-bretonne' =&gt; 'livraison_box_bretonne#index', via: :get
  
    match '/abonnements' =&gt; 'abonnements#index', via: :get
  
    devise_for :users, path: '', path_names: { sign_in: 'connexion', sign_out: 'déconnexion'}
  
    resources :users do
      delete 'déconnexion' =&gt; 'devise/sessions#destroy'
    end
  
    match '/mon-marche-breton' =&gt; 'marche_breton#index', via: :get
  
    root 'home#home'
  end
  </code></pre>
  
  <p>And the logs :</p>
  
  <pre><code>Started POST "/carts/add_item" for ::1 at 2017-05-30 09:48:52 +0200
  Processing by CartsController#add_item as HTML
    Parameters: {"authenticity_token"=&gt;"QrToQUHVxjuV5cUvZYHd7tj457htfZohOkmsvNDnKv79P413xjsSfR/8RVXtdIU7/wcmhcxjkU85N13CqJkG2w=="}
    Cart Load (0.3ms)  SELECT  `carts`.* FROM `carts` WHERE `carts`.`id` = 1 LIMIT 1
  Completed 500 Internal Server Error in 27ms (ActiveRecord: 14.9ms)
  
  ArgumentError (wrong number of arguments (given 0, expected 1)):
    app/controllers/carts_controller.rb:6:in `add_item'
  </code></pre>