【问题标题】:Rails SystemStackError (stack level too deep) in Controller控制器中的 Rails SystemStackError(堆栈级别太深)
【发布时间】:2012-07-27 03:25:25
【问题描述】:

我有一个简单的控制器在 Twitter 上进行搜索。我的搜索在 Rails 控制台上运行良好,但是当我运行它时出现堆栈溢出错误并且无法弄清楚发生了什么。我的日志文件显示了一遍又一遍运行的索引方法。

Controller 

class TimelinesController < ApplicationController
  def index
    @timelines = Twitter.search("Ford Edge", :rpp => 3, :result_type => "recent")
    respond_to do |format|
        format.html index.html.erb
        format.json { render json: @timelines }
    end
  end
end

View

<% @timelines.each do |timeline| %>
  <tr>
    <td><%= timeline.from_user %></td>
    <td><%= timeline.text %></td>
  </tr>
<% end %>

欣赏任何想法。谢谢。

【问题讨论】:

  • 您能否提供请求 TimelinesController#index 操作的代码?

标签: ruby-on-rails ruby stack-overflow


【解决方案1】:

试试:

@timelines.结果.each{...

;)

【讨论】:

    【解决方案2】:

    我认为这是违规行:format.html index.html.erb

    index.html.erb 不在引号中,因此它看起来像是对 ruby​​ 的一系列方法调用,其中第一个是 index,它导致了无限递归。

    当您在没有参数的情况下调用 format.html 时,Rails 应该为您呈现正确的模板,如果没有,请确保将模板名称用引号括起来。

    【讨论】:

    • 感谢您为我指明正确的方向。我删除了整个 respond_to 块,现在可以正常工作了。
    猜你喜欢
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    • 2013-10-05
    • 2014-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多