比如 有这样一个方法:
def create
@itouch_service = ItouchService.new(params[:itouch_service])
@member = Member.find(session[:member_id])
@itouch_service.member = @member
respond_to do |format|
if @itouch_service.save
flash[:notice] = 'ItouchService was successfully created.'
format.html { redirect_to(new_service_logo_path(@itouch_service)) }
format.xml { render :xml => @itouch_service, :status => :created, :location => @itouch_service }
else
format.html { render :action => "new" }
format.xml { render :xml => @itouch_service.errors, :status => :unprocessable_entity }
end
end
end
我测试它的时候写的方法是:
def test_create
liwan=members(:liwan_member )
post :create,{:itouch_service=>{:provider_type=>'Member',:provider_id=>1}},{:member_id=>liwan.id}
assert_response :redirect
assert_redirected_to :action=>'new_service_logo'
end
但是报错,
Expected response to be a <:redirect>,but was <200>
意思就是测试的方法并没有保存成功!所以不会重定向!但是我把这句
if @itouch_service.save中的
if去掉,把方法改为:
def create
@itouch_service = ItouchService.new(params[:itouch_service])
@member = Member.find(session[:member_id])
@itouch_service.member = @member
@itouch_service.save
respond_to do |format|
flash[:notice] = 'ItouchService was successfully created.'
format.html { redirect_to(new_service_logo_path(@itouch_service)) }
format.xml { render :xml => @itouch_service, :status => :created, :location => @itouch_service }
end
end
这样就好了,测试成功!不知道是不是if的原因还是我写的测试有问题的原因!请帮忙看以下!
分享到:
相关推荐
在实际开发中,考虑到性能和兼容性问题,可能需要考虑其他库,如EPPlus,它是一个轻量级且高效的处理Excel文件的.NET库,无需安装Office。不过,对于简单的Excel操作,如本例中的删除行,Microsoft.Office.Interop....
- 保存更改:`workbook.Save()`,如果是在新建工作簿后首次保存,需使用`workbook.SaveAs`指定文件路径 - 关闭工作簿:`workbook.Close(SaveChanges:=True/False)`,True表示保存更改,False则不保存 - 退出Excel...
在C#编程环境中,导入Excel并读取其中的图片上传是一项常见的任务,特别是在处理数据导入、数据分析或报表生成等场景。...在实际开发过程中,可能还需要考虑错误处理、性能优化等问题,以提供更健壮的解决方案。
if (p.Location == ptright && p.Image == bmpg) { change += pbox.Name + "$" + p.Name + "|"; pbox.Location = ptright; p.Location = opt; bushu++; textBox1.Enabled = false; button1.Enabled = false;...
修改了HttpPost相对路径的一些问题。 V2.2.0.0增加: [id(0x00010041), helpstring("Get Rev Index")] HRESULT GetRevCount( [out,retval] long * pbool); [id(0x00010042), helpstring("Get Rev Index Info")...
这个主题就是关于如何在VB.NET 2005环境中实现 Datagridview 数据导出到Excel,并且保持数据格式与控件样式的一致性。 首先,要导出Datagridview到Excel,你需要使用Microsoft Office Interop库,这允许你的VB.NET...
需要注意的是,使用Office Interop库可能会引发一些问题,比如需要用户电脑上安装相应的Office版本,且运行速度较慢。因此,对于大规模数据或服务器环境,推荐使用其他库,如EPPlus,它是一个基于Open XML的库,可以...
workbook.SaveAs("Path_to_save_your_excel_file.xlsx"); workbook.Close(); excelApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet); System.Runtime.InteropServices....
workbook.Save(); workbook.Close(); excelApp.Quit(); ``` 这个代码示例中,我们假设了数据从第二行开始,第一行为表头。根据实际需求,你可能需要调整这些参数。此外,这个方法可能会导致排序问题,因为删除行会...
bitmap.Save("C:\\path\\to\\screenshot.png", ImageFormat.Png); } ``` 最后,我们需要将截图插入到Word文档中。这可以通过`Range`对象的`InsertPicture`方法完成: 1. 指定插入位置:可以是当前光标位置,也...
在VB的工程资源管理器中,选择“工具”->“引用”,然后找到并勾选“Microsoft Excel xx.x Object Library”(这里的xx.x代表你的Excel版本号)。 接着,定义变量以存储Excel对象,例如`Workbook`、`Worksheet`、`...
需要注意的是,使用`Microsoft.Office.Interop.Excel`虽然方便,但可能存在性能问题,因为它需要Excel进程在后台运行。对于大规模的数据处理,可以考虑使用其他无依赖库,如EPPlus,它是一个基于.NET的Excel文件读写...
虽然本主题的参考资料中列出了一些具体的资源,但在这个回答中,我将尝试总结出一些关于在VB中控制Word的基本知识点和方法。 首先,要在VB中控制Word,你需要使用Word的对象模型。VB中的自动化,通常指的是使用一种...
- 添加“Microsoft Word xx.0 Object Library”(其中xx.0代表Word的具体版本号,例如12.0对应Word 2007)。 - 这样做后,ASP.NET会自动生成Word的COM包装类程序集,并将其添加到应用程序目录中,以便我们可以在...
在实际操作中,你还需要考虑异常处理,确保在出现问题时能正确清理资源: ```csharp try { // 上述操作 } catch (Exception ex) { Console.WriteLine("出错啦:" + ex.Message); if (wordApp != null && !...
if (worksheet.Cells[i, columnIndex].Value2 == "Search value") { Console.WriteLine("Found at row " + i); } } ``` 在实际开发中,为了提高性能和避免内存泄漏,使用完Excel对象后应正确释放它们: ```...
if (dataGridView.Rows[row].Cells=imgCol.Index].Value != null) { // 保存图片到硬盘 string imgPath = SaveImageToDisk(dataGridView.Rows[row].Cells=imgCol.Index].Value); // 插入图片到Excel Excel....
至于“邪恶版”标题,可能暗示了这个例子涉及了一些不常规或边缘性的应用,比如批量下载大量图片,这可能会对目标网站造成负担,也可能涉及侵犯用户隐私或版权问题。因此,在实际操作中,确保你的行为合法且符合道德...
./was xx.xx.xx.xx [-s object] [-d dest ][-r [-p param] ] [-l ] [s]: send a file (object) [d]: specify the destination to change into, also where the object to save [r]: run it in the server ...