title: Create object from a block of search results Ruby on Rails
body: <p>I'm building a Rails application that allows the user to create a Book object based on search results from the Google Books api. I have a controller that handles searching the api, using the GoogleBooks gem and displays the results in a list. I'm struggling to figure out a way to pass book information from a single search result into my Create action in the Books controller. </p>
  
  <p>My search controller takes params from my search form and creates a variable, @results, that I'm calling in a 'search' view. Here is my search controller:</p>
  
  <pre><code>class SearchController &lt; ApplicationController
  
      def search 
          @results = GoogleBooks.search(params[:search])
      end
  
  end
  </code></pre>
  
  <p>My view looks like this: </p>
  
  <pre><code>&lt;h1&gt;Search Results&lt;/h1&gt;
  
  &lt;% @results.each do |result| %&gt;
      &lt;ul&gt;
          &lt;li&gt;&lt;%= result %&gt;&lt;/li&gt;
          &lt;li&gt;&lt;%= result.title %&gt;&lt;/li&gt;
          &lt;li&gt;&lt;%= result.authors %&gt;&lt;/li&gt;
          &lt;li&gt;&lt;%= result.isbn %&gt;&lt;/li&gt;
          &lt;li&gt;&lt;%= result.description %&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>The problem that I'm having is that I'm not sure how to pass individual result data on to my Book controller's 'create' action to generate a new book in the database. I don't think I can pass 'result.title' or 'result.author' to the Book controller for example because they aren't instance variables and there is also no way to distinguish between each result. </p>
  
  <p>My page source for search results looks like this, if that is any help. </p>
  
  <pre><code>&lt;h1&gt;Search Results&lt;/h1&gt;
  
      &lt;ul&gt;
          &lt;li&gt;#&amp;lt;GoogleBooks::Item:0x007ff75d2bd138&amp;gt;&lt;/li&gt;
          &lt;li&gt;Kansha: Celebrating Japan&amp;#39;s Vegan and Vegetarian Traditions&lt;/li&gt;
          &lt;li&gt;Elizabeth Andoh&lt;/li&gt;
          &lt;li&gt;9781607743965&lt;/li&gt;
          &lt;li&gt;The celebration of Japan’s... &lt;/li&gt;
      &lt;/ul&gt;
      &lt;ul&gt;
          &lt;li&gt;#&amp;lt;GoogleBooks::Item:0x007ff75d2bc148&amp;gt;&lt;/li&gt;
          &lt;li&gt;Advanced Energy Saving and Its Applications in Industry&lt;/li&gt;
          &lt;li&gt;Kazuo. Matsuda, Yasuki. Kansha, Chihiro. Fushimi&lt;/li&gt;
          &lt;li&gt;9781447142072&lt;/li&gt;
          &lt;li&gt;The conventional approach for... &lt;/li&gt;
      &lt;/ul&gt;
  </code></pre>
  
  <p>I would like to use a button to allow a user to 'select' the book and then pass on the book's information to the create action. I'm thinking I need to do something like this with button_to:</p>
  
  <pre><code>&lt;%= button_to 'Create Book', book_path, :method =&gt; :post %&gt;
  </code></pre>
  
  <p>But how do I get the a single book's data to the create action?</p>