【问题标题】:Add eventbrite gem to my ruby on rails website将 eventbrite gem 添加到我的 ruby​​ on rails 网站
【发布时间】:2020-04-16 11:17:38
【问题描述】:

我正在尝试通过在我的 ruby​​ on rails 网站上使用 eventbrite 应用程序来列出我所在城市即将举行的活动 https://github.com/envoy/eventbrite

我做的是

在我的 gemfile 中

gem 'eventbrite'

在我的控制器中

  def blogs
    Eventbrite.token = "AIURA4Q6XH4KXXXMURUD"
    Eventbrite::Category.all
    Eventbrite::Subcategory.all
    Eventbrite::Format.all
  end

我应该在 blog.html.erb 的视图文件中添加什么以像这个网站 https://www.thenewparish.com/ 那样以一种很好的方式显示所有事件

我试过这个<%= Eventbrite::Category.all %>

它给了我

{ "locale": "en_US", "pagination": {"object_count":21,"page_number":1,"page_size":50,"page_count":1,"has_more_items":false}, "categories": [ {"id":"103","resource_uri":"https://www.eventbriteapi.com/v3/categories/103/","name":"Music","name_localized":"Music","short_name":"Music","short_name_localized":"Music"}, {"id":"101","resource_uri":"https://www.eventbriteapi.com/v3/categories/101/","name":"Business & Professional","name_localized":"Business & Professional","short_name":"Business","short_name_localized":"Business"}, {"id":"110","resource_uri":"https://www.eventbriteapi.com/v3/categories/110/","name":"Food & Drink","name_localized":"Food & Drink","short_name":"Food & Drink","short_name_localized":"Food & Drink"}, {"id":"113","resource_uri":"https://www.eventbriteapi.com/v3/categories/113/","name":"Community & Culture","name_localized":"Community & Culture","short_name":"Community","short_name_localized":"Community"}, {"id":"105","resource_uri":"https://www.eventbriteapi.com/v3/categories/105/","name":"Performing & Visual Arts","name_localized":"Performing & Visual Arts","short_name":"Arts","short_name_localized":"Arts"}, {"id":"104","resource_uri":"https://www.eventbriteapi.com/v3/categories/104/","name":"Film, Media & Entertainment","name_localized":"Film, Media & Entertainment","short_name":"Film & Media","short_name_localized":"Film & Media"}, {"id":"108","resource_uri":"https://www.eventbriteapi.com/v3/categories/108/","name":"Sports & Fitness","name_localized":"Sports & Fitness","short_name":"Sports & Fitness","short_name_localized":"Sports & Fitness"}, {"id":"107","resource_uri":"https://www.eventbriteapi.com/v3/categories/107/","name":"Health & Wellness","name_localized":"Health & Wellness","short_name":"Health","short_name_localized":"Health"}, {"id":"102","resource_uri":"https://www.eventbriteapi.com/v3/categories/102/","name":"Science & Technology","name_localized":"Science & Technology","short_name":"Science & Tech","short_name_localized":"Science & Tech"}, {"id":"109","resource_uri":"https://www.eventbriteapi.com/v3/categories/109/","name":"Travel & Outdoor","name_localized":"Travel & Outdoor","short_name":"Travel & Outdoor","short_name_localized":"Travel & Outdoor"}, {"id":"111","resource_uri":"https://www.eventbriteapi.com/v3/categories/111/","name":"Charity & Causes","name_localized":"Charity & Causes","short_name":"Charity & Causes","short_name_localized":"Charity & Causes"}, {"id":"114","resource_uri":"https://www.eventbriteapi.com/v3/categories/114/","name":"Religion & Spirituality","name_localized":"Religion & Spirituality","short_name":"Spirituality","short_name_localized":"Spirituality"}, {"id":"115","resource_uri":"https://www.eventbriteapi.com/v3/categories/115/","name":"Family & Education","name_localized":"Family & Education","short_name":"Family & Education","short_name_localized":"Family & Education"}, {"id":"116","resource_uri":"https://www.eventbriteapi.com/v3/categories/116/","name":"Seasonal & Holiday","name_localized":"Seasonal & Holiday","short_name":"Holiday","short_name_localized":"Holiday"}, {"id":"112","resource_uri":"https://www.eventbriteapi.com/v3/categories/112/","name":"Government & Politics","name_localized":"Government & Politics","short_name":"Government","short_name_localized":"Government"}, {"id":"106","resource_uri":"https://www.eventbriteapi.com/v3/categories/106/","name":"Fashion & Beauty","name_localized":"Fashion & Beauty","short_name":"Fashion","short_name_localized":"Fashion"}, {"id":"117","resource_uri":"https://www.eventbriteapi.com/v3/categories/117/","name":"Home & Lifestyle","name_localized":"Home & Lifestyle","short_name":"Home & Lifestyle","short_name_localized":"Home & Lifestyle"}, {"id":"118","resource_uri":"https://www.eventbriteapi.com/v3/categories/118/","name":"Auto, Boat & Air","name_localized":"Auto, Boat & Air","short_name":"Auto, Boat & Air","short_name_localized":"Auto, Boat & Air"}, {"id":"119","resource_uri":"https://www.eventbriteapi.com/v3/categories/119/","name":"Hobbies & Special Interest","name_localized":"Hobbies & Special Interest","short_name":"Hobbies","short_name_localized":"Hobbies"}, {"id":"199","resource_uri":"https://www.eventbriteapi.com/v3/categories/199/","name":"Other","name_localized":"Other","short_name":"Other","short_name_localized":"Other"},

【问题讨论】:

标签: ruby-on-rails api model-view-controller rubygems eventbrite


【解决方案1】:

这是从响应中获取数据的方法 此处显示所有类别数据是示例代码

<% response_hash = Eventbrite::Category.all %>

<% response_hash[:categories].each do |category|%>
  <%= category[:resource_uri]%>
  <%= category[:name]%>
  <%= category[:name_localized]%>
  <%= category[:short_name]%>
  <%= category[:short_name_localized]%>
<% end %>

对于分页细节也获取对象

{:object_count=&gt;21, :page_number=&gt;1, :page_size=&gt;50, :page_count=&gt;1, :has_more_items=&gt;false}

所以,你可以通过这个得到记录总数和页码

<%= response_hash[:pagination][:object_count] %>
<%= response_hash[:pagination][:page_number] %>

更多详细回复和输入,您可以访问本站

我建议您使用此站点并调用直接 API 来获取和显示数据而不是 gem,这样您将了解更多信息并更好地控制数据。

有关如何调用和传递哪些参数的更多详细信息,您可以访问此详细文档 https://www.eventbrite.com/platform/docs/events

【讨论】:

  • 谢谢!我得到了这个 eventbriteapi.com/v3/categories/103 Music Music Music Music eventbriteapi.com/v3/categories/101 Business & Professional Business & Professional Business Business... 我怎样才能让它看起来像这样 thenewparish.com
  • @nourza 我无法访问您分享的链接 我收到了401 UNAUTHORIZED
  • 你可以在这里查看结果limoexotic.com/blogs
  • 据我了解,您希望所有活动都属于您的城市并显示在您的网站上。为此,您需要使用与上面不同的方法。
  • 根据您的上述方法,您将获得所有事件类别,然后您必须获得属于这些事件类别的所有事件。 EventCtegory -&gt; get the Event. 但是您必须更改获取您所在城市的事件的方法您可以使用此选项获取您所在城市的事件all_events = Eventbrite::Event.search({q: 'Your City Name'}) 然后循环到此并从哈希中获取所有事件数据并将其显示给您的网站。
猜你喜欢
  • 2023-03-07
  • 1970-01-01
  • 2013-12-25
  • 2018-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-04
相关资源
最近更新 更多