33class PetitionsController < ApplicationController
44 before_action :redirect_to_valid_state , only : [ :index ]
55 before_action :do_not_cache , except : [ :index , :show ]
6+ before_action :set_cors_headers , only : [ :index , :show , :count ] , if : :json_request?
67
78 before_action :redirect_to_home_page_if_dissolved , only : [ :new , :check , :check_results , :create ]
89 before_action :redirect_to_home_page_unless_opened , only : [ :index , :new , :check , :check_results , :create ]
@@ -17,7 +18,6 @@ class PetitionsController < ApplicationController
1718 before_action :redirect_to_moderation_info_url , if : :in_moderation? , only : [ :gathering_support , :show ]
1819 before_action :redirect_to_petition_url , if : :moderated? , only : [ :gathering_support , :moderation_info ]
1920
20- before_action :set_cors_headers , only : [ :index , :show , :count ] , if : :json_request?
2121 after_action :set_content_disposition , if : :csv_request? , only : [ :index ]
2222
2323 def index
@@ -95,9 +95,13 @@ def redirect_to_home_page_unless_opened
9595 redirect_to home_url unless Parliament . opened?
9696 end
9797
98+ def request_format
99+ request . format . json? ? :json : nil
100+ end
101+
98102 def redirect_to_archived_petition_if_archived
99103 if petition = Archived ::Petition . find_by ( id : petition_id )
100- redirect_to archived_petition_url ( petition_id ) if petition . parliament . archived?
104+ redirect_to archived_petition_url ( petition_id , format : request_format ) if petition . parliament . archived?
101105 end
102106 end
103107
0 commit comments