title: How to display all posts in a blog application using Rails 3?
body: <p>I am trying to implement a blog application in my app.But i am getting the following  error after saving the posts.</p>
  
  <h1>Error:</h1>
  
  <pre><code>NoMethodError in Homes#blog
  
  Showing C:/Site/library_management1/app/views/homes/blog.html.erb where line #19 raised:
  
  undefined method `name' for #&lt;Array:0x21896a0&gt;
  </code></pre>
  
  <p>Actually My blog implementation story is like this.When a logged in user will add his name and comment in required place and clicked on submit button all blogs will saved as well as display.All comments should visible to all logged in users belongs to this app.Suppose one user wants to reply/edit then he/she can do this.</p>
  
  <p>My codes are as follows.</p>
  
  <h1>views/homes/blog.html.erb:</h1>
  
  <pre><code>&lt;% if current_user %&gt;
  &lt;div class="totaldiv"&gt;
    &lt;div class="navdiv"&gt;&lt;span&gt;STUDENT INFORMATION&lt;/span&gt;&lt;span&gt;Logged in as &lt;%= current_user.email %&gt;&lt;/span&gt;&lt;/div&gt;
    &lt;div class="wrapper"&gt;
    &lt;div id="leftsidebtn"&gt;
   &lt;ul&gt;
    &lt;li&gt;&lt;a href="/homes/issuebooks"&gt;Book issue&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href="/homes/availablebooks"&gt;Books Available&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href="/homes/magazines?user_id=&lt;%= current_user.id %&gt;"&gt;Magazines Purchase&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="/sessions/removeuser"&gt;Log Out&lt;/a&gt;&lt;/li&gt;
   &lt;/ul&gt;  
  &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="restdiv" id="ex3" &gt;
  &lt;center&gt;
   &lt;%= form_for :blogs,:url =&gt; {:action =&gt; 'savecomments',:id =&gt; current_user.id } do |f| %&gt;
   &lt;p&gt;
    &lt;label for="name"&gt;Name:&lt;/label&gt;
    &lt;%= f.text_field :name,placeholder:"Enter your name" %&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;label for="Comment"&gt;Comment:&lt;/label&gt;
    &lt;%= f.text_area :body,:class =&gt; "blog-navigation",placeholder:"Type your comment here" %&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;%= f.submit "Add Comments",:class =&gt;"btn btn-success" %&gt;
  &lt;/p&gt;
   &lt;% end %&gt;
   &lt;% if params[:id] %&gt;
   &lt;h1&gt;Comments&lt;/h1&gt;
   &lt;% @blogs.each do |blog| %&gt;
  &lt;div class="blog-site"&gt;
  &lt;div class="name-site"&gt;
   &lt;%= blog.name %&gt;
  &lt;/div&gt;
  &lt;div class="message-site"&gt;
    &lt;%= blog.body %&gt;
  &lt;/div&gt;
  &lt;div class="reply-site"&gt;
    &lt;%= link_to 'Replay',homes_blog_path %&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  &lt;% end %&gt;
  &lt;/center&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <h1>controller/homes_controller.rb:</h1>
  
  <pre><code>class HomesController &lt; ApplicationController
       before_filter :authenticate_admin!,only: [:admin]
      def index
  
      end
      def admin
  
      end
      def managebooks
          @books=Book.new
          if params[:id]
              @books=Book.find(params[:id])
              @book=Book.all
          end
      end
      def savebooks
          @books=Book.new(params[:books])
          if @books.save
              flash[:notice]="Data has submitted successfully"
              flash[:color]="valid"
              redirect_to :action =&gt; 'managebooks',:id =&gt; @books.id
          else
              flash[:notice]="Data couldnot submitted successfully"
              flash[:color]="invalid"
              render 'managebooks'
          end
      end
      def remove
          @books=Book.find(params[:id])
          @books.destroy
      end
      def books
  
      end
      def showbooks
          @books=Book.all
      end
      def searchbooks
          @books=Book.all
      end
      def member
          @users=User.new
      end
      def registration
          @users=User.new
      end
      def savedata
          @users=User.new(params[:users])
          if @users.save
              flash[:notice]="Data has submitted successfully"
              flash[:color]="valid"
              redirect_to :action =&gt; 'member'
          else
              flash[:notice]="Data could not submitted successfully"
              flash[:color]="invalid"
              render 'registration'
          end
      end
      def issuebooks
          @issues=Issue.new
      end
      def savedissuebooks
          @issues=Issue.new(params[:issues])
          if @issues.save
              flash[:notice]="information has saved successfully"
              flash[:color]="valid"
              redirect_to :action =&gt; 'member'
          else
              flash[:notice]="Data couldnot saved"
              flash[:color]="invalid"
              render 'issuebooks'
          end
      end
      def availablebooks
  
          @books=Book.all
      end
      def userissues
          @issues=Issue.all
      end
      def magazine
          @magazines=Magazine.new
      end
      def savemagazines
          @users=User.find(params[:id])
          @magazines=Magazine.new(params[:magazines])
          @magazines.user_id=@users.id
          if @magazines.save
              flash[:notice]="Data submitted successfully"
              flash[:color]="valid"
              redirect_to :action =&gt; "member"
          else
              flash[:notice]="Data could not saved"
              flash[:color]="invalid"
              render 'magazines'
          end
      end
      def magazineissue
          @magazines=Magazine.all
          @users=User.find @magazines.first.user_id
      end
      def blog
          if params[:id]
              @blogs=Blog.find(params[:id])
              @blogs=Blog.all
          else
          @blogs=Blog.new
          end
      end
      def savecomments
          @users=User.find(params[:id])
          @blogs=Blog.new(params[:blogs])
          @blogs.user_id=@users.id
          if @blogs.save
              flash[:notice]="Comment has been posted successfully"
              flash[:color]="valid"
              redirect_to :action =&gt; "blog",:id =&gt; params[:id]
          else
              flash[:notice]="Comment could not saved"
              flash[:color]="invalid"
              render 'blog'
          end
      end
  end
  </code></pre>
  
  <h1>model/blog.rb</h1>
  
  <pre><code>class Blog &lt; ActiveRecord::Base
    attr_accessible :body, :name
    validates :name, :presence =&gt; true, :length =&gt; {:in =&gt; 3..10}
    belongs_to :user
  end
  </code></pre>
  
  <p>Please check my all codes and let me to know where i did the mistake and kindly help me to make this blog application correctly according to my story which is explained above.</p>