Search Form Displaying Business Name with Business URL from API

109 views Asked by At

I am creating a simple search using the Yellow Pages API, coded in Ruby and Sinatra, and I'd like to display the search result business listing with a clickable URL. I have coded in both fields for "businessName" and "moreInfoURL" from the YP API, but I don't know how I can connect these both together.

Right now, they display next to each other in the search results, but I have the raw URL at the end and I'd like the more Info URL to be displayed as the link for the business name.

Here is the code I have for the results of the search form:

<% if @results %>
  <% @results.each do |result| %>
    <%= result["businessName"] %> - <%= result["phone"] %> <br />
    <%= result["street"] %> <br />
    <%= result["city"] %>, <%= result["state"] %> <%= result["zip"] %> <br />
    <%= result["moreInfoURL"] %> <br />  

Results display like this (default search for pizza in zip code 93551):

Sams Pizza - (661) 266-9626 
3011 Rancho Vista Blvd # G 
Palmdale, CA 93551 
http://c.ypcdn.com/2/c/rtd?vrid=dc0ef076051e2778f1163f862a9b68a4&rid=ad4c0564-9d2d-41af-8e3d-9a4814516d87&ptid=943aw4l8qj&ypid=4777667&lid=4777667&tl=7&lsrc=MDM&dest=http%3A%2F%2Fwww.yellowpages.com%2Fpalmdale-ca%2Fmip%2Fsams-pizza-4777667%3Ffrom%3Dpubapi_943aw4l8qj 

Any help is greatly appreciated.

1

There are 1 answers

1
Sir l33tname On BEST ANSWER

If I understand you right you can just make a link like this:

<% if @results %>
  <% @results.each do |result| %>
    <a href="<%= result["moreInfoURL"] %>"><%= result["businessName"] %></a>  - <%= result["phone"] %> <br />
    <%= result["street"] %> <br />
    <%= result["city"] %>, <%= result["state"] %> <%= result["zip"] %> <br />