开发者

Using different logic for the same respond_to format in Rails

开发者 https://www.devze.com 2023-01-21 07:48 出处:网络
My Rails application is currently usin开发者_StackOverflow中文版g 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 u

My Rails application is currently usin开发者_StackOverflow中文版g 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消