简体   繁体   English

如何在将使用诸如Yelp之类的API的Rails应用程序中实现搜索栏?

[英]How do I implement a search bar in a Rails application that will use an API such as Yelp's?

I am making a Rails application that is using Postgres as the database. 我正在制作一个使用Postgres作为数据库的Rails应用程序。 I want to be able to implement a search bar in one of my views that will get information from multiple APIs (perhaps Yelp and Eventbrite, maybe more). 我希望能够在我的一个视图中实现一个搜索栏,它将从多个API获取信息(可能是Yelp和Eventbrite,可能更多)。 It would then display the results to the user. 然后它会将结果显示给用户。

I have not decided on how to filter these results. 我还没决定如何过滤这些结果。 The user should then be able to save their favorite results, be able to look into these results' details, and share them with friends. 然后,用户应该能够保存他们喜欢的结果,能够查看这些结果的详细信息,并与朋友分享。

Which gems should I use? 我应该使用哪些宝石? What is the best way to implement this search? 实现此搜索的最佳方法是什么? Any advice would be appreciated. 任何意见,将不胜感激。

I can't speak to how to implement an entire feature since that is outside the scope of this question. 我无法谈论如何实现整个功能,因为这超出了本问题的范围。 However I can give some advice. 不过我可以提一些建议。 HTTParty is a great gem in my experience for reaching out to APIs. 在我接触API的过程中, HTTParty是一个伟大的宝石。 I would have a search_controller that the user posts to, and then have that controller use different plain ruby classes to reach out to the various APIs user HTTParty as the http client. 我会有一个用户发布的search_controller,然后让该控制器使用不同的普通ruby类来联系各种API用户HTTParty作为http客户端。

For using API's like Yelp, Evenbrite or external API's you usually have to register to get full access to them. 要使用像Yelp,Evenbrite或外部API这样的API,您通常需要注册以获得对它们的完全访问权限。 In any case, you may or may not have to login to the API. 在任何情况下,您可能也可能不必登录API。

Guessing that your search bar doesn't have autocomplete and you don't have to log in, you must create a controller that handles the search. 猜测您的搜索栏没有自动完成功能而您无需登录,您必须创建一个处理搜索的控制器。 That controller can call multiple models or wrappers, that each of one handles the API call to an specific provider. 该控制器可以调用多个模型或包装器,每个模型或包装器处理对特定提供者的API调用。

If the provider doesn't have a gem, you can use this: http://blog.teamtreehouse.com/its-time-to-httparty 如果提供者没有gem,您可以使用: http//blog.teamtreehouse.com/its-time-to-httparty

Other providers like Stripe ie, do provide a gem. 其他提供商如Stripe ie确实提供了一个宝石。 For those cases, i recommend to search in https://www.ruby-toolbox.com/ , where you can find gems (type eventbrite in the search bar of this site). 对于这些情况,我建议在https://www.ruby-toolbox.com/中搜索,您可以在其中找到宝石(在本网站的搜索栏中键入eventbrite)。 Those gems are rated by use, popularity and more. 这些宝石按使用,受欢迎等评级。 It's a good source of knowledge. 这是一个很好的知识来源。

If you need to login to API's, you probably need to register your app so you can use it via a protocol, ie Oauth, like the Github API. 如果您需要登录API,您可能需要注册您的应用程序,以便您可以通过协议使用它,即Oauth,如Github API。

如果您要使用的API遵循一种宁静的格式,我发现这个gem对于处理活动记录关联等restful API非常有用: https//rubygems.org/gems/activeresource/versions/4.0.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Rails 4.2.1应用程序中使用javascript实现显示/隐藏到搜索栏 - Implement show/hide to the search bar using javascript in rails 4.2.1 application 如何在 Rails 应用程序中实现虚 URL? - How can I implement vanity URL's in a Rails application? Ruby on rails 如何实现搜索栏功能以通过用户名查找其他用户? - Ruby on rails How can i implement search bar feature to find other user by username? 如何在 Rails 应用程序中实现 Paypal Rest API - How to implement Paypal Rest API in Rails Application 如何在Rails应用程序的附件中实现搜索文本数据 - How to implement the search text data in attached files in rails application 如何在heroku上托管的ruby on rails项目中实现弹性搜索? - How do I implement elastic search in a ruby on rails project hosted on heroku? 如何转换XML文件以在Rails应用程序中使用? - How do I convert an XML file for use in a Rails application? 如何在emberjs应用程序中使用Rails助手 - How do I use rails helper in an emberjs application 我如何知道ruby on rails应用程序是否使用数据库分区? - How do I know if a ruby on rails application use database partitioning? 如何将CSS与Rails应用程序中的ruby一起使用? - How do I use CSS with a ruby on rails application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM