title: Uncaught Error: Route parameter missing: id - Javascript console
body: <p>this is my first time trying to use ajax and javascript and I've come across this problem:</p>
  
  <p>Uncaught Error: Route parameter missing: id </p>
  
  <p>I'm not sure how to fix it/where to look as I don't understand what the error is telling me. what does 'route parameter missing: id' mean?</p>
  
  <p>I'm not sure what code is relevant to this issue so I've had a crack putting up what may be important:</p>
  
  <p>My browser shows:</p>
  
  <p><img src="https://i.stack.imgur.com/hv4MU.png" alt="javascript console in chrome"></p>
  
  <p>I think it has something to do with how the user variable is passing around but I'm not sure if this thought is on the right track or not..</p>
  
  <p>users/controller:</p>
  
  <pre><code>  def index
      @users = User.search(params[:search])
    end
  </code></pre>
  
  <p>view/users/index:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;% @users.each do |user| %&gt;
          &lt;li&gt;
              &lt;%= user.name %&gt;
              &lt;% if logged_in? %&gt;
                  &lt;div id="relationship-status"&gt;
                      &lt;% if current_user.following.include?(@user) %&gt;
                          &lt;%= link_to "Edit Relationship", edit_relationship_path(followed_id: @user), class: "btn btn-primary" %&gt;
                      &lt;% else %&gt;
                          &lt;%= link_to "Add Relationship", new_relationship_path(followed_id: @user), class: "btn btn-primary", id: 'add-relationship', data: { followed_id: @user.to_param } %&gt;
                      &lt;% end %&gt;
                  &lt;/div&gt;
              &lt;% end %&gt;   
          &lt;/li&gt;
      &lt;% end %&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>relationship_controller:</p>
  
  <pre><code>def create
      if params[:relationship] &amp;&amp; params[:relationship].has_key?(:followed_id)
        @followed = User.find(params[:relationship][:followed_id])
        # @followed = User.where(name: params[:relationship][:followed_id]).first
        @relationship = Relationship.request(current_user, @followed)
        respond_to do |format|
          if @relationship.new_record?
            format.html do
              flash[:danger] = "There was a problem creating that relationship request"
              redirect_to followed_path(@followed)
            end
            format.json { render json: @relationship.to_json, status: :precondition_failed }
          else
            format.html do
              flash[:success] = "Friend request sent"
              redirect_to followed_path(@followed)
            end
            format.json { render json: @relationship.to_json }
          end
  
        end
      else
        flash[:danger] = "Friend Required"
        redirect_to users_path
      end
    end
  </code></pre>
  
  <p>relationship.js:</p>
  
  <pre><code>$(document).ready(function() {
  
      $('#add-relationship').click(function(event) {
          event.preventDefault();
          var addRelationshipBtn = $(this);
          $.ajax({
              url: Routes.relationship_path({relationship: { followed_id: addRelationshipBtn.data('followedId') }}),
              dataType: 'json', 
              type: 'POST', 
              success: function(e) {
                  addRelationshipBtn.hide();
                  $('#relationship-status').html("&lt;a href='#' class='btn btn-success'&gt;Relationship Requested&lt;/a&gt;")
              }
          });
      });
  });
  </code></pre>
  
  <p><strong>EDIT: added in:</strong></p>
  
  <p>application.js:</p>
  
  <pre><code>// This is a manifest file that'll be compiled into application.js, which will include all the files
  // listed below.
  //
  // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
  // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
  //
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
  // compiled file.
  //
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
  // about supported directives.
  //
  //= require jquery
  //= require jquery_ujs
  //= require bootstrap
  //= require turbolinks
  //= require_tree .
  //= require js-routes
  </code></pre>
  
  <p>config/application.rb:</p>
  
  <pre><code>class Application &lt; Rails::Application
      # Settings in config/environments/* take precedence over those specified here.
      # Application configuration should go into files in config/initializers
      # -- all .rb files in that directory are automatically loaded.
  
      # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
      # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
      # config.time_zone = 'Central Time (US &amp; Canada)'
  
      # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
      # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
      # config.i18n.default_locale = :de
      config.assets.initialize_on_precompile = true
    end
  end
  </code></pre>
  
  <p>routes:</p>
  
  <p>Rails.application.routes.draw do</p>
  
  <pre><code>  root                       'static_pages#home'
    get     'help'     =&gt;      'static_pages#help'
    get     'about'    =&gt;      'static_pages#about'
    get     'contact'  =&gt;      'static_pages#contact'
    get     'signup'   =&gt;      'users#new'
    get     'login'    =&gt;      'sessions#new'
    delete  'logout'   =&gt;      'sessions#destroy'
    get     'search'   =&gt;      'users#index'
    get     'followed' =&gt;      'users#show_followed'
    resources :users do 
      member do 
        get :following, :followers
      end
    end
    resources :sessions,            only: [:new, :create, :destroy]
    resources :account_activations, only: [:edit]
    resources :password_resets,     only: [:new, :create, :edit, :update]
    resources :profiles,            only: [:edit, :update, :destroy] do
      put :email, on: :member
    end
    resources :relationships,       only: [:new, :create, :index, :edit, :accept, :destroy] do
      member do
        put :accept
      end
    end
  </code></pre>