我有一个具有这种结构的凤凰路由器:
defmodule Hexlet.Router do
use Hexlet.Web, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/api", Hexlet do
pipe_through :api
resources "/sessions", SessionController, only: [:create, :delete]
end
end
我从浏览器向我的api发送AJAX请求。我可以通过localhost:4000/api/sessions
与我联系,但我不能localhost:4000/api/sessions.json
。我希望反过来。我怎么能这样做?
我知道rails通过向范围添加constraints: { format: :json }
来实现此功能。