Use relative URLs where possible

In general, we always use relative URLs (using `_path`), but sometimes
we were accidentally using absolute URLs (using `_url`). It's been
reported i might cause some isuses if accepting both HTTP and HTTPS
connections, although we've never seen the case.

In any case, this change makes the code more consistent and makes the
generated HTML cleaner.
This commit is contained in:
Javi Martín
2019-10-11 03:06:24 +02:00
parent 11e52dbe98
commit 27468b0b7b
22 changed files with 58 additions and 53 deletions

View File

@@ -5,7 +5,7 @@ class Admin::Poll::ActivePollsController < Admin::Poll::BaseController
def create def create
if @active_poll.update(active_poll_params) if @active_poll.update(active_poll_params)
redirect_to admin_polls_url, notice: t("flash.actions.update.active_poll") redirect_to admin_polls_path, notice: t("flash.actions.update.active_poll")
else else
render :edit render :edit
end end
@@ -16,7 +16,7 @@ class Admin::Poll::ActivePollsController < Admin::Poll::BaseController
def update def update
if @active_poll.update(active_poll_params) if @active_poll.update(active_poll_params)
redirect_to admin_polls_url, notice: t("flash.actions.update.active_poll") redirect_to admin_polls_path, notice: t("flash.actions.update.active_poll")
else else
render :edit render :edit
end end

View File

@@ -60,7 +60,7 @@ class Admin::Widget::CardsController < Admin::BaseController
if @card.site_customization_page_id if @card.site_customization_page_id
redirect_to admin_site_customization_page_cards_path(page), notice: notice redirect_to admin_site_customization_page_cards_path(page), notice: notice
else else
redirect_to admin_homepage_url, notice: notice redirect_to admin_homepage_path, notice: notice
end end
end end

View File

@@ -4,7 +4,7 @@ module AccessDeniedHandler
included do included do
rescue_from CanCan::AccessDenied do |exception| rescue_from CanCan::AccessDenied do |exception|
respond_to do |format| respond_to do |format|
format.html { redirect_to main_app.root_url, alert: exception.message } format.html { redirect_to main_app.root_path, alert: exception.message }
format.json { render json: { error: exception.message }, status: :forbidden } format.json { render json: { error: exception.message }, status: :forbidden }
end end
end end

View File

@@ -32,7 +32,7 @@ class Management::UsersController < Management::BaseController
def logout def logout
destroy_session destroy_session
redirect_to management_root_url, notice: t("management.sessions.signed_out_managed_user") redirect_to management_root_path, notice: t("management.sessions.signed_out_managed_user")
end end
private private

View File

@@ -36,7 +36,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
set_flash_message(:notice, :success, kind: provider.to_s.capitalize) if is_navigational_format? set_flash_message(:notice, :success, kind: provider.to_s.capitalize) if is_navigational_format?
else else
session["devise.#{provider}_data"] = auth session["devise.#{provider}_data"] = auth
redirect_to new_user_registration_url redirect_to new_user_registration_path
end end
end end

View File

@@ -26,7 +26,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
def delete def delete
current_user.erase(erase_params[:erase_reason]) current_user.erase(erase_params[:erase_reason])
sign_out sign_out
redirect_to root_url, notice: t("devise.registrations.destroyed") redirect_to root_path, notice: t("devise.registrations.destroyed")
end end
def success def success

View File

@@ -3,11 +3,13 @@ module DirectUploadsHelper
def render_destroy_upload_link(direct_upload) def render_destroy_upload_link(direct_upload)
label = direct_upload.resource_relation == "image" ? "images" : "documents" label = direct_upload.resource_relation == "image" ? "images" : "documents"
link_to t("#{label}.form.delete_button"), link_to t("#{label}.form.delete_button"),
direct_upload_destroy_url("direct_upload[resource_type]": direct_upload.resource_type, direct_upload_destroy_path(
"direct_upload[resource_type]": direct_upload.resource_type,
"direct_upload[resource_id]": direct_upload.resource_id, "direct_upload[resource_id]": direct_upload.resource_id,
"direct_upload[resource_relation]": direct_upload.resource_relation, "direct_upload[resource_relation]": direct_upload.resource_relation,
"direct_upload[cached_attachment]": direct_upload.relation.cached_attachment, "direct_upload[cached_attachment]": direct_upload.relation.cached_attachment,
format: :json), format: :json
),
method: :delete, method: :delete,
remote: true, remote: true,
class: "delete remove-cached-attachment" class: "delete remove-cached-attachment"

View File

@@ -19,10 +19,12 @@ module DocumentsHelper
def render_destroy_document_link(builder, document) def render_destroy_document_link(builder, document)
if !document.persisted? && document.cached_attachment.present? if !document.persisted? && document.cached_attachment.present?
link_to t("documents.form.delete_button"), link_to t("documents.form.delete_button"),
direct_upload_destroy_url("direct_upload[resource_type]": document.documentable_type, direct_upload_destroy_path(
"direct_upload[resource_type]": document.documentable_type,
"direct_upload[resource_id]": document.documentable_id, "direct_upload[resource_id]": document.documentable_id,
"direct_upload[resource_relation]": "documents", "direct_upload[resource_relation]": "documents",
"direct_upload[cached_attachment]": document.cached_attachment), "direct_upload[cached_attachment]": document.cached_attachment
),
method: :delete, method: :delete,
remote: true, remote: true,
class: "delete remove-cached-attachment" class: "delete remove-cached-attachment"
@@ -38,13 +40,13 @@ module DocumentsHelper
accept: accepted_content_types_extensions(document.documentable_type.constantize), accept: accepted_content_types_extensions(document.documentable_type.constantize),
class: "js-document-attachment", class: "js-document-attachment",
data: { data: {
url: document_direct_upload_url(document), url: document_direct_upload_path(document),
nested_document: true nested_document: true
} }
end end
def document_direct_upload_url(document) def document_direct_upload_path(document)
direct_uploads_url("direct_upload[resource_type]": document.documentable_type, direct_uploads_path("direct_upload[resource_type]": document.documentable_type,
"direct_upload[resource_id]": document.documentable_id, "direct_upload[resource_id]": document.documentable_id,
"direct_upload[resource_relation]": "documents") "direct_upload[resource_relation]": "documents")
end end

View File

@@ -28,10 +28,12 @@ module ImagesHelper
def render_destroy_image_link(builder, image) def render_destroy_image_link(builder, image)
if !image.persisted? && image.cached_attachment.present? if !image.persisted? && image.cached_attachment.present?
link_to t("images.form.delete_button"), link_to t("images.form.delete_button"),
direct_upload_destroy_url("direct_upload[resource_type]": image.imageable_type, direct_upload_destroy_path(
"direct_upload[resource_type]": image.imageable_type,
"direct_upload[resource_id]": image.imageable_id, "direct_upload[resource_id]": image.imageable_id,
"direct_upload[resource_relation]": "image", "direct_upload[resource_relation]": "image",
"direct_upload[cached_attachment]": image.cached_attachment), "direct_upload[cached_attachment]": image.cached_attachment
),
method: :delete, method: :delete,
remote: true, remote: true,
class: "delete remove-cached-attachment" class: "delete remove-cached-attachment"
@@ -47,7 +49,7 @@ module ImagesHelper
accept: imageable_accepted_content_types_extensions, accept: imageable_accepted_content_types_extensions,
class: "js-image-attachment", class: "js-image-attachment",
data: { data: {
url: image_direct_upload_url(imageable), url: image_direct_upload_path(imageable),
nested_image: true nested_image: true
} }
end end
@@ -59,8 +61,8 @@ module ImagesHelper
show_caption: show_caption show_caption: show_caption
end end
def image_direct_upload_url(imageable) def image_direct_upload_path(imageable)
direct_uploads_url("direct_upload[resource_type]": imageable.class.name, direct_uploads_path("direct_upload[resource_type]": imageable.class.name,
"direct_upload[resource_id]": imageable.id, "direct_upload[resource_id]": imageable.id,
"direct_upload[resource_relation]": "image") "direct_upload[resource_relation]": "image")
end end

View File

@@ -3,5 +3,5 @@
<h2><%= t("admin.active_polls.edit.title") %></h2> <h2><%= t("admin.active_polls.edit.title") %></h2>
<div class="polls-form"> <div class="polls-form">
<%= render "form", form_url: admin_active_polls_url(@active_poll) %> <%= render "form", form_url: admin_active_polls_path(@active_poll) %>
</div> </div>

View File

@@ -3,7 +3,7 @@
<span><%= investment.formatted_price %></span> <span><%= investment.formatted_price %></span>
<% if @budget.balloting? %> <% if @budget.balloting? %>
<%= link_to budget_ballot_line_url(id: investment.id, <%= link_to budget_ballot_line_path(id: investment.id,
investments_ids: investment_ids), investments_ids: investment_ids),
title: t("budgets.ballots.show.remove"), title: t("budgets.ballots.show.remove"),
class: "remove-investment-project", class: "remove-investment-project",

View File

@@ -28,7 +28,7 @@
</p> </p>
<% if investment.should_show_ballots? %> <% if investment.should_show_ballots? %>
<%= link_to t("budgets.investments.investment.add"), <%= link_to t("budgets.investments.investment.add"),
budget_ballot_lines_url(investment_id: investment.id, budget_ballot_lines_path(investment_id: investment.id,
budget_id: investment.budget_id, budget_id: investment.budget_id,
investments_ids: investment_ids), investments_ids: investment_ids),
class: "button button-support small expanded", class: "button button-support small expanded",

View File

@@ -55,7 +55,7 @@
</div> </div>
<% end %> <% end %>
<%= render("shared/advanced_search", search_path: budget_investments_url(@budget)) %> <%= render("shared/advanced_search", search_path: budget_investments_path(@budget)) %>
<% if unfeasible_or_unselected_filter %> <% if unfeasible_or_unselected_filter %>
<ul class="no-bullet submenu"> <ul class="no-bullet submenu">

View File

@@ -11,8 +11,7 @@
<% else %> <% else %>
<% if dashboard_action.request_to_administrators && !dashboard_action.requested_for?(proposal) %> <% if dashboard_action.request_to_administrators && !dashboard_action.requested_for?(proposal) %>
<%= form_for @dashboard_executed_action, <%= form_for @dashboard_executed_action,
url: create_request_proposal_dashboard_action_url(proposal, url: create_request_proposal_dashboard_action_path(proposal, dashboard_action) do |f| %>
dashboard_action) do |f| %>
<%= f.submit(class: "button", value: t("dashboard.form.request")) %> <%= f.submit(class: "button", value: t("dashboard.form.request")) %>
<% end %> <% end %>
<% end %> <% end %>

View File

@@ -9,6 +9,6 @@
<h1><%= t("proposals.edit.editing") %></h1> <h1><%= t("proposals.edit.editing") %></h1>
<%= render "form", form_url: legislation_process_proposal_url(@proposal.legislation_process_id, @proposal) %> <%= render "form", form_url: legislation_process_proposal_path(@proposal.legislation_process_id, @proposal) %>
</div> </div>
</div> </div>

View File

@@ -5,6 +5,6 @@
<h1><%= t("proposals.new.start_new") %></h1> <h1><%= t("proposals.new.start_new") %></h1>
<%= render "legislation/proposals/form", form_url: legislation_process_proposals_url, id: @proposal.id %> <%= render "legislation/proposals/form", form_url: legislation_process_proposals_path, id: @proposal.id %>
</div> </div>
</div> </div>

View File

@@ -6,7 +6,7 @@
<div class="small-12 medium-9 column end"> <div class="small-12 medium-9 column end">
<h2><%= t("management.proposals.create_proposal") %></h2> <h2><%= t("management.proposals.create_proposal") %></h2>
<%= render "proposals/form", form_url: management_proposals_url %> <%= render "proposals/form", form_url: management_proposals_path %>
</div> </div>
</div> </div>

View File

@@ -9,6 +9,6 @@
<h1><%= t("proposals.edit.editing") %></h1> <h1><%= t("proposals.edit.editing") %></h1>
<%= render "form", form_url: proposal_url(@proposal) %> <%= render "form", form_url: proposal_path(@proposal) %>
</div> </div>
</div> </div>

View File

@@ -9,7 +9,7 @@
<%= t("proposals.new.more_info") %> <%= t("proposals.new.more_info") %>
<% end %> <% end %>
</div> </div>
<%= render "proposals/form", form_url: proposals_url %> <%= render "proposals/form", form_url: proposals_path %>
</div> </div>
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">

View File

@@ -20,7 +20,7 @@
<% @geozones.each do |geozone| %> <% @geozones.each do |geozone| %>
<area shape="poly" <area shape="poly"
coords="<%= geozone.html_map_coordinates %>" coords="<%= geozone.html_map_coordinates %>"
href="<%= polymorphic_url(@resource, search: geozone.name) %>" href="<%= polymorphic_path(@resource, search: geozone.name) %>"
title="<%= geozone.name %>" title="<%= geozone.name %>"
alt="<%= geozone.name %>"> alt="<%= geozone.name %>">
<% end %> <% end %>

View File

@@ -24,7 +24,7 @@
limit: @limit) %> limit: @limit) %>
</strong> </strong>
<%= link_to t("shared.suggest.#{resource_name}.see_all"), <%= link_to t("shared.suggest.#{resource_name}.see_all"),
polymorphic_url(resource_model, search: @search_terms) %> polymorphic_path(resource_model, search: @search_terms) %>
</p> </p>
<% end %> <% end %>

View File

@@ -9,8 +9,8 @@ describe "Email campaigns" do
end end
scenario "Track email templates" do scenario "Track email templates" do
3.times { visit root_url(track_id: campaign1.track_id) } 3.times { visit root_path(track_id: campaign1.track_id) }
5.times { visit root_url(track_id: campaign2.track_id) } 5.times { visit root_path(track_id: campaign2.track_id) }
visit admin_stats_path visit admin_stats_path
click_link campaign1.name click_link campaign1.name
@@ -24,8 +24,8 @@ describe "Email campaigns" do
end end
scenario "Do not track erroneous track_ids" do scenario "Do not track erroneous track_ids" do
visit root_url(track_id: campaign1.track_id) visit root_path(track_id: campaign1.track_id)
visit root_url(track_id: "999") visit root_path(track_id: "999")
visit admin_stats_path visit admin_stats_path
click_link campaign1.name click_link campaign1.name