真正的代码:将json发送给控制器时NoMethodError'title_url'?
class TitlesController < ApplicationController
respond_to :json
def create
title = Title.create!(params[:title])
respond_with title
end
end
规格:
describe TitlesController do
it 'receives a json response' do
post :create, title: { name: 'fancy title'}, format: 'json'
expect(controller).to respond_with(201)
end
end
==> NoMethodError:对#
未定义的方法`title_url”世界为什么会这样想打电话title_url? ?????
找出您是否在代码库中的某处使用了'title_url'。运行'grep -rin“title_url”*' –
@patrick,我不确定。但请尝试在测试中将格式作为符号传递。还要确保格式是作为'json'传递的 – usha