From 80104d100f46a0975a104a31b26b69c02a9530c7 Mon Sep 17 00:00:00 2001
From: Josep Jaume Rey Peroy
Date: Sat, 12 Dec 2015 10:22:27 +0100
Subject: [PATCH] Normalize page paths
Normalize page paths so they can be accessed by `page_path(:id)`.
The benefit of this is that we can add any arbitrary amount of pages
without affecting the routing layer.
---
app/controllers/pages_controller.rb | 49 +----------------------
app/views/layouts/_footer.html.erb | 10 ++---
app/views/layouts/_header.html.erb | 2 +-
app/views/pages/more_information.html.erb | 16 ++++----
config/routes.rb | 20 ++-------
spec/controllers/pages_controller_spec.rb | 29 ++++++--------
6 files changed, 31 insertions(+), 95 deletions(-)
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index 805e7aebc..c00bcf95b 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -1,52 +1,7 @@
class PagesController < ApplicationController
skip_authorization_check
- def accessibility
- end
-
- def census_terms
- end
-
- def conditions
- end
-
- def general_terms
- end
-
- def privacy
- end
-
- def coming_soon
- end
-
- def how_it_works
- end
-
- def how_to_use
- end
-
- def more_information
- end
-
- def opendata
- end
-
- def participation
- end
-
- def proposals_info
- end
-
- def participation_facts
- end
-
- def participation_world
- end
-
- def verify
- end
-
- def blog
- redirect_to "http://diario.madrid.es/participa/"
+ def show
+ render action: params[:id]
end
end
diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb
index b170aa431..411d32675 100644
--- a/app/views/layouts/_footer.html.erb
+++ b/app/views/layouts/_footer.html.erb
@@ -13,7 +13,7 @@
consul: link_to(t("layouts.footer.consul"), t("layouts.footer.consul_url"), target: "blank")).html_safe
%>
<%= t("layouts.footer.contact_us") %>
- <%= link_to t("layouts.footer.faq"), faq_path %>
+ <%= link_to t("layouts.footer.faq"), page_path('faq') %>
@@ -45,10 +45,10 @@
<%= t("layouts.footer.copyright", year: Time.now.year) %> |
- <%= link_to t("layouts.footer.more_info"), "/more_information" %> |
- <%= link_to t("layouts.footer.privacy"), "/privacy" %> |
- <%= link_to t("layouts.footer.conditions"), "/conditions" %> |
- <%= link_to t("layouts.footer.accessibility"), "/accessibility" %>
+ <%= link_to t("layouts.footer.more_info"), page_path('/more_information') %> |
+ <%= link_to t("layouts.footer.privacy"), page_path('privacy') %> |
+ <%= link_to t("layouts.footer.conditions"), page_path('conditions') %> |
+ <%= link_to t("layouts.footer.accessibility"), page_path('/accessibility') %>
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb
index 4c5bac804..67012211e 100644
--- a/app/views/layouts/_header.html.erb
+++ b/app/views/layouts/_header.html.erb
@@ -57,7 +57,7 @@
<%= link_to t("layouts.header.debates"), debates_path, class: ("active" if current_page?(controller: "/debates")) %>
<%= link_to t("layouts.header.proposals"), proposals_path, class: ("active" if current_page?(controller: "/proposals")) %>
- <%= link_to t("layouts.header.more_information"), "/more_information", class: ("active" if current_page?("/more_information")) %>
+ <%= link_to t("layouts.header.more_information"), page_path('more_information'), class: ("active" if current_page?("/more_information")) %>
<%= link_to t("layouts.header.external_link_blog_url"), target: "_blank" do %>
<%= t("layouts.header.external_link_blog") %>
diff --git a/app/views/pages/more_information.html.erb b/app/views/pages/more_information.html.erb
index 3215c7249..cdc4afc05 100644
--- a/app/views/pages/more_information.html.erb
+++ b/app/views/pages/more_information.html.erb
@@ -5,49 +5,49 @@
<%= t('pages.titles.more_information') %>
-
- <%= link_to how_it_works_path do %>
+ <%= link_to page_path('how_it_works') do %>
<%= t('pages.more_information.titles.how_it_works') %>
<%= t('pages.more_information.description.how_it_works') %>
<% end %>
-
- <%= link_to how_to_use_path do %>
+ <%= link_to page_path('how_to_use') do %>
<%= t('pages.more_information.titles.how_to_use') %>
<%= t('pages.more_information.description.how_to_use') %>
<% end %>
-
- <%= link_to participation_path do %>
+ <%= link_to page_path('participation') do %>
<%= t('pages.more_information.titles.participation') %>
<%= t('pages.more_information.description.participation') %>
<% end %>
-
- <%= link_to proposals_info_path do %>
+ <%= link_to page_path('proposals_info') do %>
<%= t('pages.more_information.titles.proposals_info') %>
<%= t('pages.more_information.description.proposals_info') %>
<% end %>
-
- <%= link_to participation_world_path do %>
+ <%= link_to page_path('participation_world') do %>
<%= t('pages.more_information.titles.participation_world') %>
<%= t('pages.more_information.description.participation_world') %>
<% end %>
-
- <%= link_to participation_facts_path do %>
+ <%= link_to page_path('participation_facts') do %>
<%= t('pages.more_information.titles.participation_facts') %>
<%= t('pages.more_information.description.participation_facts') %>
<% end %>
-
- <%= link_to faq_path do %>
+ <%= link_to page_path('faq') do %>
<%= t('pages.more_information.titles.faq') %>
<%= t('pages.more_information.description.faq') %>
<% end %>
-
- <%= link_to proposals_info_path(:anchor => "iii") do %>
+ <%= link_to page_path('proposals_info', :anchor => "iii") do %>
<%= t('pages.more_information.titles.signature_sheet') %>
<%= t('pages.more_information.description.signature_sheet') %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 75c4ce695..f85578c6b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -259,21 +259,7 @@ Rails.application.routes.draw do
end
# static pages
- get "/census_terms", to: "pages#census_terms"
- get "/conditions", to: "pages#conditions"
- get "/general_terms", to: "pages#general_terms"
- get "/privacy", to: "pages#privacy"
- get "/coming_soon", to: "pages#coming_soon"
- get "/how_it_works", to: "pages#how_it_works"
- get "/how_to_use", to: "pages#how_to_use"
- get "/more_information", to: "pages#more_information"
- get "/opendata", to: "pages#opendata"
- get "/participation", to: "pages#participation"
- get "/proposals_info", to: "pages#proposals_info"
- get "/participation_facts", to: "pages#participation_facts"
- get "/participation_world", to: "pages#participation_world"
- get "/faq", to: "pages#faq"
- get "/blog", to: "pages#blog"
- get "/accessibility", to: "pages#accessibility"
- get "/verifica", to: "verification/letter#edit"
+
+ get '/blog' => redirect("http://diario.madrid.es/participa/")
+ resources :pages, path: '/', only: [:show]
end
diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb
index d80533bc9..4efd7d7c8 100644
--- a/spec/controllers/pages_controller_spec.rb
+++ b/spec/controllers/pages_controller_spec.rb
@@ -4,68 +4,63 @@ describe PagesController do
describe 'Static pages' do
it 'should include a privacy page' do
- get :privacy
+ get :show, id: :privacy
expect(response).to be_ok
end
it 'should include a conditions page' do
- get :conditions
+ get :show, id: :conditions
expect(response).to be_ok
end
it 'should include a general terms page' do
- get :general_terms
+ get :show, id: :general_terms
expect(response).to be_ok
end
it 'should include a terms page' do
- get :census_terms
+ get :show, id: :census_terms
expect(response).to be_ok
end
end
describe 'Provisional pages' do
it 'should include a opendata page' do
- get :opendata
+ get :show, id: :opendata
expect(response).to be_ok
end
end
describe 'Info pages' do
it 'should include a coming_soon page' do
- get :coming_soon
+ get :show, id: :coming_soon
expect(response).to be_ok
end
it 'should include a how_it_works page' do
- get :how_it_works
+ get :show, id: :how_it_works
expect(response).to be_ok
end
it 'should include a how_to_use page' do
- get :how_to_use
+ get :show, id: :how_to_use
expect(response).to be_ok
end
it 'should include a more_information page' do
- get :more_information
+ get :show, id: :more_information
expect(response).to be_ok
end
it 'should include a participation page' do
- get :participation
+ get :show, id: :participation
expect(response).to be_ok
end
- it 'should include a blog page' do
- get :blog
- expect(response).to be_redirect
- end
-
it 'should include a accessibility page' do
- get :accessibility
+ get :show, id: :accessibility
expect(response).to be_ok
end
end
-end
\ No newline at end of file
+end