My Rails application is currently using JSON as the respond_to
format for AJAX forms on the site. I'm planning to create a public API for the application, and I'd like to use JSON for it also. How might I distinguish between an AJAX form and an API call in my controllers if the requested format for both is JSON?
views:
16answers:
1
+2
A:
I'd recommend you keep the public api in a separate controller, and have a different route since you say you have different logic. You can have namespaced controllers such as app/controllers/api/users_controller.rb
and namespace your routes like:
namespace :admin do
resources :users
end
and leave your existing controllers with ajax actions used by your site as they are.
Jeremy
2010-10-24 10:38:14