Undefined method name for nil:NilClass

Bgbkcfzbwecyd

New Member
I am having this problem for too long now and I can't find out where is the problem, so: \[code\] Showing /home/alex/Desktop/personal/app/views/entries/list.html.erb where line #17 raised: undefined method `name' for nil:NilClassExtracted source (around line #17):14: <% @entries.each do |entry| %>15: <tr>16: <td><%= link_to entry.title, :action => "show", :id => entry.id %></td>17: <td><%= link_to entry.category.name, :action => "list", :category_id => entry.category.id %></td>18: </tr>19: <% end %> 20: \[/code\]My views/entries/list.html.erb looks looks like this:\[code\]<html> <head> <title>All Entries</title> </head> <body> <h1>Online Personal Collection- All Entries</h1> <table border="1"> <tr> <td width="80%"><p align="center"><i><b>Entry</b></i></td> <td width="20%"><p align="center"><i><b>Category</b></i></td> </tr> <% @entries.each do |entry| %> <tr> <td><%= link_to entry.title, :action => "show", :id => entry.id %></td> <td><%= link_to entry.category.name, :action => "list", :category_id => entry.category.id %></td> </tr> <% end %> </table> <p><%= link_to "Create new entry", :action => "new" %></p> <br /> <%=link_to "Back to Index", entries_path%> <br /> <%=link_to "Back to Account Info", my_account_path%> <br /> <h3>Enter keyword</h3><form action ="search" method="post"><input name = "key" type="input" /><input value="http://stackoverflow.com/questions/13807817/Send" type="submit"/></form></body> </html>\[/code\]The models are like this: \[code\]class Entry < ActiveRecord::Base attr_accessible :comments, :date, :description, :title, :category_id, :category_name belongs_to :categoryafter_create do |entry| logger.info "entry created: #{entry.title} #{entry.description}"endendclass Category < ActiveRecord::Base attr_accessible :name has_many :entriesend\[/code\]And the entries_controller :\[code\]class EntriesController < ApplicationController # GET /entries # GET /entries.json def index @entries = Entry.all respond_to do |format| format.html # index.html.erb format.json { render json: @entries } end end def list if params[ :category_id].nil? @entries = Entry.find(:all) else @entries = Entry.find(:all , :conditions => ["category_id = ?" , params[ :category_id]]) params[ :category_id] = nil respond_to do |format| format.html # list.html.erb format.json { render json: @entry } end end end # GET /entries/1 # GET /entries/1.json def show @entry = Entry.find(params[:id]) @category = Category.find(:all) respond_to do |format| format.html # show.html.erb format.json { render json: @entry } end end # GET /entries/new # GET /entries/new.json def new @entry = Entry.new @categories= Category.find(:all) respond_to do |format| format.html # new.html.erb format.json { render json: @entry } end end # GET /entries/1/edit def edit @entry = Entry.find(params[:id]) @categories = Category.find(:all) end # POST /entries # POST /entries.json def create @entry = Entry.new(params[:entry]) respond_to do |format| if @entry.save format.html { redirect_to @entry, notice: 'Entry was successfully created.' } format.json { render json: @entry, status: :created, location: @entry } else format.html { render action: "new" } format.json { render json: @entry.errors, status: :unprocessable_entity } end end end # PUT /entries/1 # PUT /entries/1.json\[/code\]Now if someone spot the problem and could help me understand where I'm doing wrong I will be grateful. Thanks! Alex.
 
Back
Top