How to implement confirmation or preview in rails? <p>I am calling JSON api from my rails app. User inputs a name in a form, Then i call JSON API and find if the name has any matches there. Sometimes its just one so i create entry with the data provided in JSON. But most of the times there are multiple results on the JSON, How do i implement "Hey i found multiple results for same name, which one were you looking for?" and then the users chooses which one he/she was intending and then it creates an entry in database. </p> <p>I wrote a simple script to test out the JSON.</p> <pre><code>data = JSON.load response if data['results'].empty? #if the JSON data is empty puts "There was no movie found. Did you spell the movie name correctly?" elsif data['results'].count &gt; 1 #if JSON Data has more than one result data['results'].each do |movie| Movie::Movies &lt;&lt; Movie.new(movie['id'], movie['title'], movie['release_year'], (imdb_url + movie['imdb']).to_s, movie['rating'], movie['poster_120x171'], movie['poster_240x342'], movie['poster_400x570']) end Movie::Movies.each do |movie| puts "#{movie.title} : #{movie.release_year}" end else #IF JSON has only one entry movie = Movie.new(data['results'][0]['id'], data['results'][0]['title'], data['results'][0]['release_year'], (imdb_url + data['results'][0]['imdb']).to_s, data['results'][0]['rating'], data['results'][0]['poster_120x171'], data['results'][0]['poster_240x342'], data['results'][0]['poster_400x570']) end </code></pre> <p>And here is my controller at the moment. It can only handle the first record from the Hash provided by JSON. I have no clue on how to handle the situation if there are multiple results. </p> <pre><code> def create require 'rest_client' require 'json' imdb_url = 'http://www.imdb.com/title/' movie_title = movie_params['title'].delete(' ') response = RestClient.get "http://api-public.guidebox.com/v1.43/US/xxxxxxxxxxxxxxxx&lt;api-key&gt;/search/movie/title/#{movie_title}" data = JSON.load response @movie = Movie.new #i am doing this because my for was giving error. if data['results'].empty? flash[:alert] = "Did you spell the Title correctly? Or Maybe we could not find the movie you are looking for." render 'new' elsif data['results'].count &gt; 2 #Display all results to the user for them to pick what they really intended and create an entry of whaterver they choose. else @movie = Movie.new(gb_id: data['results'][0]['id'], title: data['results'][0]['title'], release_year: data['results'][0]['release_year'], imdb_link: (imdb_url + data['results'][0]['imdb']).to_s, rating: data['results'][0]['rating'], small_img: data['results'][0]['poster_120x171'], med_img: data['results'][0]['poster_240x342'], large_img: data['results'][0]['poster_400x570']) if @movie.save flash[:notice] = 'Movie has been successfully Added.' redirect_to @movie else flash[:alert] = "Something went wrong. Please try again." render 'new' end end end </code></pre> <p>Also in my create action i had to call the <code>@movie = Movie.new</code> again because the form was giving me errors.</p>