Ezequiel Ramiro
Ezequiel Ramiro

Reputation: 760

Ruby routes - stack level too deep

I've got the following controller:

class HomeController < ApplicationController

    def index
    end

    def next_match
        games = Invite.where('estado = "Confirmado" AND (user_id = ? OR postulation_id = ?) AND game_date >= ?',
        params[:user_id], params[:user_id], Date.today)
        respond_to do |format|
            format.json {   render json: games}
            end

    end
    private
    def params
        params.require(:games).permit(:user_id)
    end
end 

In my routes file I declare a post route to access to "next_match" method. But when I try it out I get 'stack level too deep' error. Why is that?

Routes>

  get 'home/index'
  post '/games' => 'home#next_match'
  root 'home#index'

The idea is to get some data throught post methon inside my first page.

Thank you.

Upvotes: 1

Views: 71

Answers (1)

leifg
leifg

Reputation: 9008

You have a method called params that calls itself over and over again (recursion).

Try naming it something else:

def allowed_params
   params.require(:games).permit(:user_id)
end

Upvotes: 4

Related Questions