diff options
author | Azul <azul@riseup.net> | 2016-08-18 11:00:16 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-08-19 11:15:31 +0200 |
commit | fbad882075e745ab7afbe5f89c67544fb3c607c3 (patch) | |
tree | d55e4c4dd3a6612e04e0fd40e736c8b6d4342762 /app/controllers/application_controller.rb | |
parent | 20bb76848b852bba9ab3c99b1c2a68464585bd56 (diff) |
respond_to on a per controller basis
If you inherit respond to and call it again in your controller
it will not overwrite the previous but add to it.
Since we always have some exceptions from the rules it's probably
easiest to be explicit in the controllers that require it themselves.
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 61ced21..8d08a2c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,33 +1,25 @@ class ApplicationController < ActionController::Base protect_from_forgery - before_action :check_mime_types before_filter :set_locale before_filter :no_cache_header before_filter :no_frame_header before_filter :language_header + + # UPGRADE: this won't be needed in Rails 5 anymore as it's the default + # behavior if a template is present but a different format would be + # rendered and that template is not present + before_filter :verify_request_format!, if: :mime_types_specified + rescue_from StandardError, :with => :default_error_handler rescue_from CouchRest::Exception, :with => :default_error_handler ActiveSupport.run_load_hooks(:application_controller, self) - # by default we only respond to html. - # If you want to respond with json you are probably working on - # an ApiController. - respond_to :html - protected - # UPGRADE: this won't be needed in Rails 5 anymore as it's the default - # behavior if a template is present but a different format would be - # rendered and that template is not present - def check_mime_types - mimes = collect_mimes_from_class_level() - return if mimes.empty? - - collector = ActionController::MimeResponds::Collector.new(mimes, request.variant) - unless collector.negotiate_format(request) - raise ActionController::UnknownFormat - end + def mime_types_specified + mimes = collect_mimes_from_class_level + mimes.present? end def default_error_handler(exc) |