【发布时间】:2020-07-10 20:09:10
【问题描述】:
我正在修复一些测试,以下测试的第一行给了我这个错误 ActionController::MissingExactTemplate: EventsController#index 缺少请求格式的模板:text/html。
test "#index should respond to the correct format" do
get :index, params: {id: @event.id, format: :html} #<-- this line causes problems
assert_response :success
get :index, params: {id: @event.id, format: :json}
assert_response :success
end
我认为错误是指控制器中的以下方法。
def index
@events = Event.upcoming.recent
respond_to do |format|
format.html # index.html.erb
format.json { render json: @events }
end
end
我开始认为这条线没用,但我仍然不确定。
【问题讨论】:
-
正如稍后的错误状态,您需要在您的 app/views/events 文件夹中创建一个名为 index.html.erb 的文件
标签: ruby-on-rails ruby testing