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?
Asked
Active
Viewed 283 times
0

Jimmy
- 35,686
- 13
- 80
- 98
1 Answers
2
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
- 4,880
- 1
- 19
- 15