From d81c3e5ec8936bebc57ce79b6a30b1ce04890c3a Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 21 May 2020 17:22:22 -0500 Subject: [PATCH] Move campaigns/index.json to jbuilder --- app/views/campaigns/index.jbuilder | 7 +++++++ app/views/campaigns/index.rabl | 9 --------- config/routes.rb | 8 +++++++- spec/controllers/campaigns_spec.rb | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 app/views/campaigns/index.jbuilder delete mode 100644 app/views/campaigns/index.rabl diff --git a/app/views/campaigns/index.jbuilder b/app/views/campaigns/index.jbuilder new file mode 100644 index 00000000..799fa599 --- /dev/null +++ b/app/views/campaigns/index.jbuilder @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +json.data @campaigns do |campaign| + json.extract! campaign, :name, :total_raised, :goal_amount, :id + json.url campaign_locateable_url(campaign) +end \ No newline at end of file diff --git a/app/views/campaigns/index.rabl b/app/views/campaigns/index.rabl deleted file mode 100644 index d180c586..00000000 --- a/app/views/campaigns/index.rabl +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -object false - -child @campaigns => :data do - collection @campaigns, object_root: false - attributes :name, :total_raised, :goal_amount, :url, :id -end diff --git a/config/routes.rb b/config/routes.rb index 6e1f8e6d..c8c09e9e 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -230,7 +230,7 @@ Rails.application.routes.draw do # Campaigns match 'campaigns' => 'campaigns#index', via: %i[get post] - match 'campaigns/:campaign_slug' => 'campaigns#show', via: %i[get post] + match 'campaigns/:campaign_slug' => 'campaigns#show', via: %i[get post], as: :campaign_location match 'campaigns/:campaign_slug/supporters' => 'campaigns/supporters#index', via: %i[get post] @@ -245,6 +245,12 @@ Rails.application.routes.draw do end end + direct :campaign_locateable do |model| + nonprofit = model.nonprofit + {controller: 'campaigns', action: "show", state_code: nonprofit.state_code_slug, city: nonprofit.city_slug, name: nonprofit.slug, + campaign_slug: model.slug} + end + # Misc get '/pages/wp-plugin', to: redirect('/help/wordpress-plugin') # temporary, until WP plugin updated diff --git a/spec/controllers/campaigns_spec.rb b/spec/controllers/campaigns_spec.rb index 14ff9127..fb0c0fb0 100644 --- a/spec/controllers/campaigns_spec.rb +++ b/spec/controllers/campaigns_spec.rb @@ -85,7 +85,7 @@ describe CampaignsController, type: :controller do name: 'simplename', total_raised: 0, goal_amount: 444, - url: "/nm/albuquerque/new-mexico-equality/campaigns/slug_#{campaign.id}" + url: "http://test.host/nm/albuquerque/new-mexico-equality/campaigns/slug_#{campaign.id}" }]}.with_indifferent_access) end end