我试图通过点击按钮来保存显示的网页(就像点击浏览器中的“另存为”按钮一样),但我无法弄清楚这个错误:
Missing template shipments/save_page_xls, application/save_page_xls with {:locale=
[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched i
n: * "/home/andres/Documents/Aptana Studio 3 Workspace/EcuadorCargo/app/views" * "
/var/lib/gems/1.9.1/gems/devise-2.1.2/app/views" * "/var/lib/gems/1.9.1/gems/twitt
er-bootstrap-rails-2.1.1/app/views"
我认为问题在于渲染函数不应该在控制器中,或者渲染函数没有找到正确的布局文件。我基于这个页面 rails: emulate "Save page as" behaviour
查看(以haml为单位):
= link_to "Save as XLS", save_page_xls_shipments_path, :class => 'btn btn-primary'
控制器文件:
class ShipmentsController < ApplicationController
def save_page_xls
#this is the magic line!
send_data(render, :filename => "archivo.xls")
end
end
路线:
resources :shipments, :only => :index do
collection do
get 'save_page_xls'
end
end