【发布时间】:2021-12-24 22:20:54
【问题描述】:
我有一个渲染 json 的端点:
def controller_method
render json: json_response
end
但是,我对路线的命名约定感到好奇。以下命名导致ActionController::UnknownFormat Controller#controller_method is missing a template for this request format and variant.:
get '/controller/controller_method.json', to: 'controller#controller_method'
但是,当路由命名时,我成功获取了 json:
get '/controller/controller_method_data', to: 'controller#controller_method'
我不允许在 url 路由中输入.json 吗?有什么方法可以让.json 成为路线的名称?
【问题讨论】:
标签: ruby-on-rails json routes