title: Transferring data from one view to another in Rails
body: <p>I am new to Rails and am making an e-commerce website.
  This is what the code for my view is like (this is a part of the code and not the whole thing):-</p>
  
  <pre><code>&lt;% @thriller.each do |book|%&gt;
    &lt;div class="thumbnail"&gt;
      &lt;img src="http://placehold.it/320x150" alt=""&gt;
      &lt;div class="caption"&gt;
        &lt;h4 class="pull-right"&gt;&lt;%=book.mrp%&gt;&lt;/h4&gt;
        &lt;h4&gt;&lt;a href="#"&gt;&lt;%=book.book_name%&gt;&lt;/a&gt;
        &lt;/h4&gt;
      &lt;/div&gt;
      &lt;p&gt;No. of pages:&lt;%=book.pages%&gt;&lt;/p&gt;
      &lt;br&gt;
      &lt;p&gt;In stock:&lt;%=book.stock %&gt;&lt;/p&gt;
      &lt;br&gt;
      &lt;p&gt;Synopsis:&lt;%=book.synopsis %&gt;&lt;/p&gt;
      &lt;br&gt;
      &lt;p&gt;Author:&lt;%=book.author %&gt;&lt;/p&gt;
      &lt;br&gt;
      &lt;p&gt;Publisher:&lt;%=book.publisher %&gt;&lt;/p&gt;
      &lt;br&gt;
      &lt;p&gt;Genre:&lt;%=book.genre_name%&gt;&lt;/p&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;div class="ratings"&gt;
        &lt;p&gt;
          &lt;span class="glyphicon glyphicon-star"&gt;&lt;/span&gt;
          &lt;span class="glyphicon glyphicon-star"&gt;&lt;/span&gt;
          &lt;span class="glyphicon glyphicon-star"&gt;&lt;/span&gt;
          &lt;span class="glyphicon glyphicon-star"&gt;&lt;/span&gt;
        &lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  &lt;/div&gt;
  
  &lt;div class="col-sm-4 col-lg-4 col-md-4"&gt;
    &lt;% @classic.each do|book|%&gt;
      &lt;div class="thumbnail"&gt;
        &lt;img src="http://placehold.it/320x150" alt=""&gt;
        &lt;div class="caption"&gt;
          &lt;h4 class="pull-right"&gt;&lt;%=book.mrp%&gt;&lt;/h4&gt;
          &lt;h4&gt;&lt;a href="#"&gt;&lt;%=book.book_name%&gt;&lt;/a&gt;&lt;/h4&gt;
        &lt;/div&gt;
        &lt;p&gt;No. of pages:&lt;%=book.pages%&gt;&lt;/p&gt;
        &lt;br&gt;
        &lt;p&gt;In stock:&lt;%=book.stock %&gt;&lt;/p&gt;
        &lt;br&gt;
        &lt;p&gt;Synopsis:&lt;%=book.synopsis %&gt;&lt;/p&gt;
        &lt;br&gt;
        &lt;p&gt;Author:&lt;%=book.author %&gt;&lt;/p&gt;
        &lt;br&gt;
        &lt;p&gt;Publisher:&lt;%=book.publisher %&gt;&lt;/p&gt;
        &lt;br&gt;
        &lt;p&gt;Genre:&lt;%=book.genre_name%&gt;&lt;/p&gt;
        &lt;br&gt;
        &lt;br&gt;
          &lt;div class="ratings"&gt;
            &lt;p&gt;
              &lt;span class="glyphicon glyphicon-star"&gt;&lt;/span&gt;
              &lt;span class="glyphicon glyphicon-star"&gt;&lt;/span&gt;
              &lt;span class="glyphicon glyphicon-star"&gt;&lt;/span&gt;
              &lt;span class="glyphicon glyphicon-star"&gt;&lt;/span&gt;
            &lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The controller for this has the following code:-</p>
  
  <pre><code>class ShopController &lt; ApplicationController
    def accessories
      @ntbk=Notebook.all
      @bkmk=Bookmark.all
    end
  
    def books
      @thriller=Book.where(genre_id:1)
      @classic=Book.where(genre_id:2)
      @romance=Book.where(genre_id:3)
      @selfhelp=Book.where(genre_id:4)
      @autob=Book.where(genre_id:5)
    end
  end
  </code></pre>
  
  <p>I want the user to be able to click a button and be redirected to a page which displays the details of that particular item. How should I go about doing so?</p>
  
  <p>Console log:-</p>
  
  <pre><code>Processing by ShopController#view as 
    Book Load (0.2ms)  SELECT  "books".* FROM "books" WHERE "books"."book_id" IS NULL LIMIT ?  [["LIMIT", 1]]
    Rendering shop/view.html.erb within layouts/application
    Rendered shop/view.html.erb within layouts/application (5.2ms)
  Completed 500 Internal Server Error in 14ms (ActiveRecord: 0.2ms)
  
  
  
  ActionView::Template::Error (undefined method `each' for nil:NilClass):
      1: &lt;% @book.each do|book|%&gt;
      2: &lt;p&gt;Name:&lt;%=@book.book_name%&gt;&lt;/p&gt;
      3: &lt;br&gt;
      4: &lt;p&gt;No. of pages:&lt;%=@book.pages%&gt;&lt;/p&gt;
  
  app/views/shop/view.html.erb:1:in `_app_views_shop_view_html_erb__1842756845584902456_69979582064500'
    Rendering /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout
    Rendering /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
    Rendered /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (4.7ms)
    Rendering /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
    Rendered /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.8ms)
    Rendering /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
    Rendered /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.7ms)
    Rendered /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (23.0ms)
  </code></pre>