soppliger
soppliger

Reputation: 51

Rails SystemStackError (stack level too deep) in Controller

I have a simple controller doing a search on the Twitter. My search works fine from the rails console, but I'm getting a stack overflow error when I run this and can't figure out what's going on. My log file shows the index method running over and over.

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 %>

Appreciate any thoughts. Thanks.

Upvotes: 2

Views: 2673

Answers (2)

Florin
Florin

Reputation: 528

Try:

@timelines.results.each{...

;)

Upvotes: 0

cjhveal
cjhveal

Reputation: 5791

I think this is the offending line: format.html index.html.erb

index.html.erb is not in quotes so it looks like a sequence of method calls to ruby, The first of which is index, which is causing the infinite recursion.

Rails should render the right template for you when you call format.html without an argument, and if not, make sure to wrap the template name in quotes.

Upvotes: 2

Related Questions