title: How do I pass params to Rails controller method then return value using JQuery/AJAX?
body: <p>I am using a click function to first get the array/position, then post it via an AJAX call to a controller method. I would then like the method to return a boolean value to enable the addClass in the jquery function. The console is consistently throwing a 500 server error.</p>
  
  <p>Here is the .js file:</p>
  
  <pre><code>   $(document).ready(function(){
       $("#backboard").on("click", "div", function(e){
         $("#backboard div").removeClass("selected");
         var val = $(this).data('val');
       $.ajax ({
          type: 'POST',
          url: "https://localhost:3000/chess/:pos",
          data: {pos: {value: val}},
          success: function(d){
            if(d === true){
              $(this).addClass("selected").append("&lt;p&gt;"+val+"&lt;p&gt;");
            }
          }
        });
      });
    });
  </code></pre>
  
  <p>here is the controller.rb file:</p>
  
  <pre><code> class ChessController &lt; ApplicationController
      include ChessHelper
  
      def new
      @select = false
      @game = Game.new("white", "ARSEFACE!!!")
      @arr = @game.board
      @cpu = @game.cpuName
      @player = @game.playerName
  
  
  
     end
  
     def select
        pos = params[:pos]
       a = pos[0]
       b = pos[1]
  
       if(@arr[a][b][0]===@color)
          @select = !@select
       end
  
       respond_to do |format|
         format.json { render json: @select }
        end
      end
    end
  </code></pre>
  
  <p>Here is the config/routes.rb:</p>
  
  <pre><code>   get '/chess', to: 'chess#new'
     post '/chess/:pos' =&gt; 'chess#select' 
  </code></pre>
  
  <p>I know I am probably missing something incredibly obvious here, but any help would be appreciated!</p>
  
  <p>PS and the val variable taking the data from the tag does actually have a value. I am trying to pass that value to the controller in order to return true or false, and will eventually be a validation function once I get this basic issue worked out.</p>