简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM