Ruby - error rendering a view referencing a loop that I never wrote

I have this controller:

class AlexesController < ApplicationController
  # GET /alexes
  # GET /alexes.json
  def index
    #@alexes = Alex.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @alexes }
    end
  end

  # GET /alexes/1
  # GET /alexes/1.json
  def show
  #  @alex = Alex.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @alex }
    end
  end

  # GET /alexes/new
  # GET /alexes/new.json
  def new
    @alex = Alex.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @alex }
    end
  end

  # GET /alexes/1/edit
  def edit
    @alex = Alex.find(params[:id])
  end

  # POST /alexes
  # POST /alexes.json
  def create
    @alex = Alex.new(params[:alex])

    respond_to do |format|
      if @alex.save
        format.html { redirect_to @alex, notice: 'Alex was successfully created.' }
        format.json { render json: @alex, status: :created, location: @alex }
      else
        format.html { render action: "new" }
        format.json { render json: @alex.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /alexes/1
  # PUT /alexes/1.json
  def update
    @alex = Alex.find(params[:id])

    respond_to do |format|
      if @alex.update_attributes(params[:alex])
        format.html { redirect_to @alex, notice: 'Alex was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @alex.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /alexes/1
  # DELETE /alexes/1.json
  def destroy
    @alex = Alex.find(params[:id])
    @alex.destroy

    respond_to do |format|
      format.html { redirect_to alexes_url }
      format.json { head :no_content }
    end
  end
end

It gets called when this link gets pressed:

<%= link_to "Alex Link", alexes_path(@alex) %>

so I am assuming that the get-all part of the controller would get invoked, and I commented out lines in the controller that I thought would get invoked, but I still get this error:

undefined method `each' for nil:NilClass

from line 10:

7:     <th></th>
8:   </tr>
9: 
10: <% @alexes.each do |alex| %>
11:   <tr>
12:     <td><%= link_to 'Show', alex %></td>
13:     <td><%= link_to 'Edit', edit_alex_path(alex) %></td>

Any idea where the problem is happening?

Thanks!

Answers


<%= link_to "Alex Link", alexes_path(@alex) %>

=>

<%= link_to "Alex Link", alex_path(@alex) %>

or

<%= link_to "Alex Link", @alex %>

Need Your Help

How would I open a .txt file within a jar file? Using Java?

java eclipse file jar

the line of code I'm using is: InputStream is = game.class.getResourceAsStream("testing.txt"); but when I read the file it outputs null, however in the file there is the word "test", but when I run...

Attachment name and file extension not working in email *.eml

php email zend-framework email-attachments eml

I want to create email files in .eml format with multiple attachments in. The attachments are generated and the content of the attachments are correct. But the attachments always come in .dat forma...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.