2

我正在尝试通过单击按钮来保存显示的网页(就像单击浏览器中的“另存为”按钮一样),但我无法弄清楚这个错误:

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"

我认为问题在于渲染函数不应该在控制器中,或者渲染函数没有找到正确的布局文件。我基于this page rails:模拟“将页面另存为”行为

查看(以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
4

0 回答 0