summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/application_controller.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 2af2f29..61ced21 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,5 +1,6 @@
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
@@ -9,8 +10,26 @@ class ApplicationController < ActionController::Base
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
+ end
+
def default_error_handler(exc)
respond_to do |format|
format.json { render_json_error(exc) }