我有以下测试:
it "should respond with a json object" do
xhr :post, :create, :upload => @attr_upload, :format => :json
end
这是我的路线:
resources :uploads, :except =>[:new, :show]
我有一个表单,用户可以使用jquery-file-upload插件上传图像:
<%= form_for @upload, :html => { :multipart => true } do |f| %>
<div class="fileupload-buttonbar">
<label class="fileinput-button">
<span>Add files... or drop them to upload</span>
<%= f.file_field :photo, :id => "upload_photo" %>
</label>
</div>
<% end %>
在我的控制器中,我加载文件并生成一个json响应:
def create
@upload = Upload.new(params[:upload])
respond_to do |format|
if @upload.save
set_current_upload(@upload)
format.json {render :json => [ @upload.to_jq_upload ].to_json}
else
format.json {render :json => [ @upload.to_jq_upload.merge({ :error => "custom_failure" }) ].to_json}
end
end
end
当我运行测试时,我得到以下内容:
No route matches {:action=>"update", :controller=>"uploads", :id=>#<Upload id: nil, created_at: nil, updated_at: nil, photo_file_name: nil, photo_content_type: nil, photo_file_size: nil, photo_updated_at: nil, uploadable_id: nil, uploadable_type: nil>}
任何人都可以帮助我让这个测试工作吗? 我正在提交创建操作,为什么要尝试进行更新操作?
任何帮助将不胜感激,我已经为此工作了两天。
答案 0 :(得分:0)
请求继续更新操作,而非创建,因此请使用生成的表单及其网址仔细检查模板