将Eventbrite宝石添加到我在Rails网站上的红宝石中

时间:2020-04-16 11:17:38

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

我正在尝试通过在Rails网站上的ruby上使用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"},

1 个答案:

答案 0 :(得分:1)

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

iainn

有关分页详细信息,请同时获取对象

<% 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=>21, :page_number=>1, :page_size=>50, :page_count=>1, :has_more_items=>false}

有关响应和输入的更多详细信息,您可以访问此网站

我建议您使用此站点并调用直接API来获取和显示数据,而不是通过gem来获取数据,这样您将学到更多信息并对数据进行更多控制。

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

相关问题