【问题标题】:Ruby routes - stack level too deepRuby 路由 - 堆栈级别太深
【发布时间】:2017-01-23 03:29:31
【问题描述】:

我有以下控制器:

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 

在我的路由文件中,我声明了一个访问“next_match”方法的发布路由。但是当我尝试它时,我得到“堆栈级别太深”的错误。这是为什么呢?

路线>

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

这个想法是通过我的第一页中的 post 方法获取一些数据。

谢谢。

【问题讨论】:

    标签: ruby-on-rails ruby routes


    【解决方案1】:

    您有一个名为params 的方法,它一遍又一遍地调用自身(递归)。

    尝试将其命名为其他名称:

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

    【讨论】:

    • 非常感谢。
    猜你喜欢
    • 2013-10-05
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 2013-10-05
    • 2011-11-17
    • 2012-07-24
    相关资源
    最近更新 更多