Rails Routes - 限制资源的可用格式 [英] Rails Routes - Limiting the available formats for a resource

查看:14
本文介绍了Rails Routes - 限制资源的可用格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列资源,我只希望通过 JS 格式访问这些资源.Rails 的路由资源为我提供了格式和标准 HTML.有没有办法指定只创建JS格式的路由?

I have a series of resources that I want only available if accessed via the JS format. Rails' route resources gives me the formats plus the standard HTML. Is there a way to specify that only the JS format routes be created?

推荐答案

您只需添加有关格式的约束:

You just add constraints about format :

resources :photos, :constraints => {:format => /(js|json)/}

这篇关于Rails Routes - 限制资源的可用格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆