【发布时间】:2011-07-24 15:44:51
【问题描述】:
我试图像这样在我的 TestCase 中执行 get:
request.env['CONTENT_TYPE'] = 'application/json'
get :index,:application_name=>"Heka"
虽然,它失败了:
ActionView::MissingTemplate: Missing template alarm_events/index with {:handlers=>[:builder, :haml, :erb, :rjs, :rhtml, :rxml], :locale=>[:en, :en], :formats=>[:html]
尽管在我的控制器中我有:
respond_to :html, :json
def index
@alarm_events=[...]
respond_with @alarm_events do |format|
format.json{
render :json=>@alarm_events.map{|e| e.to_portal_representation}.to_json,
:content_type=>'application/json'
}
end
end
我到底应该如何在 TestCase 上编写预期的请求?
当我在浏览器中请求 alarm_events.json 时,它工作正常。
谢谢
【问题讨论】:
标签: ruby-on-rails ruby json ruby-on-rails-3 rest