title: Why do I get "NameError in Discussions"?
body: <p>I'm currently working on a Ruby on Rails application that involves users creating discussions and commenting with microposts.  It's a pretty simple concept but I'm new and have run into some trouble. </p>
  
  <p>When trying to look at the discussions page (index of discussion) I get the error "NameError in Discussions#index":</p>
  
  <pre><code>undefined local variable or method `discussion' for #&lt;#&lt;Class:0x00000100c6e020&gt;:0x0000010380edd8&gt;
  </code></pre>
  
  <p>This is my Discussion controller:</p>
  
  <pre><code>class DiscussionsController &lt; ApplicationController
    before_filter :signed_in_user, only: [:index, :edit, :update]
  
  
    def show
      @user = User.find(params[:id])
      @discussions = @user.discussion.paginate(page: params[:page])
      @microposts = @user.micropost.paginate(page: params[:page])
    end
  
    def index
      @discussions = Discussion.all
    end
  
    def create
      @discussion = current_user.discussions.build(params[:discussion])
      if @discussion.save
        flash[:success] = "Discussion Started!"
        redirect_to root_url
      else
        render 'static_pages/home'
      end
    end
  
    def destroy
    end
  
    def edit
    end
  
    def update
    end
  
    def new
    end
  end
  </code></pre>
  
  <p>This is my Micropost form:</p>
  
  <pre><code>&lt;% @micropost = Micropost.new %&gt;
  &lt;% @micropost.discussion_id = discussion.id %&gt;
  
  &lt;%= form_for(@micropost) do |f| %&gt;
      &lt;%= render 'shared/error_messages', object: f.object %&gt;
      &lt;div class="field"&gt;
        &lt;%= f.text_area :content, placeholder: "Compose new micropost..." %&gt;
      &lt;/div&gt;
      &lt;%= f.hidden_field :discussion_id, discussion.id%&gt;
  
      &lt;%= f.submit "Post", class: "btn btn-large btn-primary" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This is my Discussion partial:</p>
  
  <pre><code>&lt;% content_for :script do %&gt;
      &lt;%= javascript_include_tag 'hover_content' %&gt;
  &lt;% end %&gt;
  
  &lt;li&gt;
    &lt;div class = "intro-bar"&gt;&lt;span class = "intro"&gt;&lt;%=discussion.intro %&gt;&lt;/span&gt;&lt;/div&gt;
    &lt;div class = "content-bar"&gt;
      &lt;span class = "content"&gt;&lt;%= discussion.content %&gt;&lt;/span&gt;
      &lt;div class = "buttons"&gt;
        &lt;div class = "vote-neg"&gt;&lt;%= link_to "Break Up", signup_path,class: "btn btn-large btn-breakup" %&gt;&lt;/div&gt;
        &lt;div class = "vote-plus"&gt;&lt;%= link_to "Stay Together", signup_path,class: "btn btn-large btn-staytogether" %&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  
  &lt;span class = "timestamp"&gt;
      Posted &lt;%= time_ago_in_words(discussion.created_at) %&gt; ago.
    &lt;/span&gt;
  
  &lt;div class = "comments"&gt;
    &lt;% discussion.microposts.each do |micropost| %&gt;
        &lt;li&gt;
          &lt;div class = "post-comment"&gt;&lt;%= micropost.content%&gt;&lt;/div&gt;
        &lt;/li&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  
  &lt;% if signed_in? %&gt;
      &lt;div class = "row"&gt;
        &lt;aside class = "span4"&gt;
          &lt;section&gt;
            &lt;%= render 'shared/micropost_form', :locals =&gt; {:discussion =&gt; discussion }%&gt;
          &lt;/section&gt;
        &lt;/aside&gt;
      &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This is my Micropost controller:</p>
  
  <pre><code>class MicropostsController &lt; ApplicationController
    before_filter :signed_in_user, only: [:create, :destroy]
  
    def index
    end
  
    def create
      @discussion = current_user.discussions.new
      @micropost = current_user.microposts.build(params[:micropost])
       if @micropost.save
         flash[:success] = "Posted!"
         redirect_to root_url
       else
         render 'static_pages/home'
       end
    end
  
    def destroy
    end
  end
  </code></pre>
  
  <p>This is my Discussion model:</p>
  
  <pre><code>class Discussion &lt; ActiveRecord::Base
    attr_accessible :content, :intro
    has_many :microposts, dependent: :destroy
  
    belongs_to :user
  
    validates :content, presence: true, length: { maximum: 600 }
    validates :intro, presence: true
  
    default_scope order: 'discussions.created_at DESC'
  end
  </code></pre>
  
  <p>This is my User model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    attr_accessible :email, :username, :age, :sex, :points, :password, :password_confirmation
    has_secure_password
    has_many :microposts, dependent: :destroy
    has_many :discussions, dependent: :destroy
  
  
    before_save {|user| user.email = email.downcase}
    before_save :create_remember_token
  
    validates :username, presence: true, length: {maximum: 15}
    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
    validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: {case_sensitive: false}
    validates :age, presence: true
    validates :sex, presence: true
    validates :password, presence: true, length: { minimum: 6 }
    validates :password_confirmation, presence: true
  
    private
  
    def create_remember_token
      self.remember_token = SecureRandom.urlsafe_base64
    end
  
  end
  </code></pre>
  
  <p>This is my Discussion index:</p>
  
  <pre><code>&lt;% provide(:title, "Discussions") %&gt;
  &lt;h1&gt;Discussions&lt;/h1&gt;
  &lt;ul class = "discussions"&gt;
    &lt;% @discussions.each do |discussion| %&gt;
        &lt;li&gt;
          &lt;%= render :partial =&gt;"discussions/discussion", :locals=&gt;{:discussion=&gt;discussion} %&gt;
        &lt;/li&gt;
    &lt;% end %&gt;
  &lt;/ul&gt;
  </code></pre>