lilyxue
lilyxue

Reputation: 23

undefined local variable or method `feed_item` in 10.3.3 of Michael Hart's Ruby on Rails Tutorial

When I run 'rails s'and visit the URL 'http://localhost:3000',error occurred

ActionView::Template::Error (undefined local variable or method `feed_item` for #<#<Class:0xb7c6d9c>:0xb7c6310>):
1: <li id="<%= feed_item.id %>">
2: <%= link_to gravatar_for(feed_item.user), feed_item.user %>
3: <span class="user">
4: <%= link_to feed_item.user.name,feed_item.user %>
app/views/shared/_feed_item.html.erb:1:in `_app_views_shared__feed_item_html_erb___55615773_95474750`
app/views/shared/_feed.html.erb:3:in `_app_views_shared__feed_html_erb__499283038_95518450`
app/views/static_pages/home.html.erb:14:in `_app_views_static_pages_home_html_erb___238258941_96211170` `

1.app/views/shared/_feed_item.html.erb

<li id="<%= feed_item.id %>">
<%= link_to gravatar_for(feed_item.user), feed_item.user %>
<span class="user">
<%= link_to feed_item.user.name,feed_item.user %>
</span>
<span class="content"><%=feed_item.content %></span>
<span class="timestamp">
Posted <%=time_ago_in_words(feed_item.created_at) %>ago.
</span>
</li>

2.app/views/shared/_feed.html.erb

<% if @feed_items.any? %>
<ol class="microposts">
<%= render partial:'shared/feed_item',collecton:@feed_items %>
</ol>
<%= will_paginate @feed_items%>
<%end%>

3.app/controllers/static_pages_controller.rb

class StaticPagesController < ApplicationController
  def home
if signed_in?
@micropost = current_user.microposts.build
@feed_items = current_user.feed.paginate(page:params[:page])

end

  end
  def help
  end

  def about
  end

  def show
  end
  def contact
  end
end

4.app/views/static_pages/home.html.erb

 <% if signed_in? %>
    <div class="row" >
    <aside class="span4" >
    <section>
    <%= render 'shared/user_info' %>
    </section>
    <section>
    <%=render 'shared/micropost_form' %>
    </section>
    </aside>

    <div class="span8">
    <h3>Micropost Feed </h3>
    <%= render 'shared/feed' %>
    </div>
    </div>

    <%else%>
    <div class="center hero-unit">
    <h1>Welcome to the Sample App</h1>
    <h2>
    This is the home page for the 
    <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
    sample application.
    </h2>
    <%= link_to "Sign up now",signup_path,class: "btn btn-large btn-primary" %>
    </div>

    <%= link_to image_tag("rails.png",alt: "Rails"),'http://`rubyonrails`.org/' %>
    <%end%>

Upvotes: 0

Views: 106

Answers (2)

Herk
Herk

Reputation: 181

You have misspelled collection in app/views/shared/_feed.html.erb line 3, try changing it to: <%= render partial:'shared/feed_item', collection: @feed_items %>

You can also find the reference implementation here which should help you compare the code.

Upvotes: 1

Jorge de los Santos
Jorge de los Santos

Reputation: 4643

If I'm right and you copied and pasted:

<ol class="microposts">
<%= render partial:'shared/feed_item', collecton: @feed_items %>
</ol>

You have a typo in app/views/shared/_feed.html.erb

Should be collection

Upvotes: 1

Related Questions