I have a series of resources that I want only available if accessed via the JS format. Rails\' route resources gives me the formats plus the standard HTML. Is there a way
You can use a before_filter that raises a routing error unless the request format is MIME::JS.
app/controllers/application_controller.rb:
class ApplicationController < ActionController::Base
before_filter :check_js
private
def check_js
raise RoutingError.new('expected application/json') unless request.format == MIME::JS
end
end
Apply this filter more surgically with :only, :except, and :skip_before_filter as covered in the rails Action Controller Guide