0

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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.