【发布时间】:2009-12-20 02:12:10
【问题描述】:
我想创建一个 .erb 文件作为许多只返回 JSON 的微小操作的输出。所以路线类似于:
map.json 'contacts_json', :controller => 'contacts', :action => 'get_json'
map.json 'cal_json', :controller => 'calendar', :action => 'get_json'
...
但这需要我创建一个联系人 erb 和一个日历 erb 等等。有没有办法明确告诉他们使用 json erb?比如:
map.json 'contacts_json', :controller => 'contacts', :action => 'get_json', :view => 'layouts/json.html.erb'
【问题讨论】:
-
为什么不直接使用控制器操作中所需的布局和视图 .. render :template => 'shared/my.json.erb'
标签: ruby-on-rails json routes