小编rom*_*mus的帖子

通过检查Content-Type进行RSpec send_file测试

我有一个Rails控制器,它发送一个具有不同Content-Type的文件

Exel-File的示例,控制器设置Content-Type = "application/excel"

这是RSpec测试:

describe "GET getfile" do
  it "Excel File" do
    controller.stub(:render)
    controller.should_receive(:send_file)
    get :getfile, :name => 'test+xls'
    controller.response.header.should == '???'
  end
end
Run Code Online (Sandbox Code Playgroud)

测试的答案是:

1) ExportController GET getfile Excel File
   Failure/Error: controller.response.header.should == ''
     expected: ""
          got: {"Content-Type"=>"text/html; charset=utf-8"} (using ==)
     Diff:
     @@ -1,2 +1,2 @@
     -""
     +"Content-Type" => "text/html; charset=utf-8"
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails sendfile

5
推荐指数
1
解决办法
2494
查看次数

如何实现Back Link到来自的页面

我有一个关联的应用程序,并将页面分页.

主对象"cat_list"的索引页面显示了指向"data_lists"关联的链接.索引页面也有"will_paginate"的分页

  1. 我显示例如page = 3"/ cat_lists?page = 3"
  2. 我点击"data_lists"的链接,例如"/ cat_lists/8984/data_lists"

此索引页面显示包含Edit,Destroy和New链接的data_lists列表.并且cat_lists索引页面的后向链接现在为"/ cat_lists"

实现这些功能的最佳做法是什么,Back Link现在来自哪个页面?

will-paginate ruby-on-rails-3

0
推荐指数
1
解决办法
1169
查看次数