【问题标题】:Search Form Displaying Business Name with Business URL from API使用 API 中的业务 URL 显示业务名称的搜索表单
【发布时间】:2013-04-23 23:07:18
【问题描述】:

我正在使用用 Ruby 和 Sinatra 编码的 Yellow Pages API 创建一个简单的搜索,并且我想显示带有可点击 URL 的搜索结果企业列表。我已经在 YP API 的“businessName”和“moreInfoURL”这两个字段中进行了编码,但我不知道如何将它们连接在一起。

现在,它们在搜索结果中彼此相邻显示,但我在末尾有原始 URL,我希望将更多信息 URL 显示为公司名称的链接。

这是我的搜索表单结果的代码:

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

结果显示如下(默认搜索邮政编码 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 

非常感谢任何帮助。

【问题讨论】:

    标签: ruby api search sinatra yellow-pages


    【解决方案1】:

    如果我理解正确,您可以创建这样的链接:

    <% 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 />
    

    【讨论】:

    • 完美。就是这么简单,不知道为什么看不到!
    猜你喜欢
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    • 2018-02-24
    • 2015-10-11
    • 1970-01-01
    相关资源
    最近更新 更多