我有一个显示报告的表格,但我需要 3 个功能,即print to pdf
,print to excel
和还通过 html 本身显示预览js
这是仅对pdf
andexcel
和 and 都适用的第一个条件。
控制器:
respond_to do |format|
if params[:print]
format.html { redirect_to :action => "report", :format => "pdf", :start_period => params[:start_period], :end_period => params[:end_period], :warehouse => params[:warehouse] }
elsif params[:excel]
format.html { redirect_to :action => "report", :format => "xls", :start_period => params[:start_period], :end_period => params[:end_period], :warehouse => params[:warehouse] }
else
format.html
end
end
看法:
<%= form_tag(models_path, :method => "get") do %>
<%= submit_tag "#{t 'pdf'}", :name => "print" %>
<%= submit_tag "#{t 'excel'}", :name => "excel" %>
<% end %>
但是当我开始通过添加预览功能时js
,它不是错误,而是两个提交按钮(pdf n excel)都指向 js。
新控制器
respond_to do |format|
if params[:print]
format.html { redirect_to :action => "report", :format => "pdf", :start_period => params[:start_period], :end_period => params[:end_period], :warehouse => params[:warehouse] }
elsif params[:excel]
format.html { redirect_to :action => "report", :format => "xls", :start_period => params[:start_period], :end_period => params[:end_period], :warehouse => params[:warehouse] }
else
format.html
format.js # NEW LINE
end
end
新观点
<%= form_tag(models_path, :method => "get", :id => "headers_search") do %>
<%= submit_tag "#{t 'ep.submit'}", :name => nil, :remote => true %>
<%= submit_tag "#{t 'pdf'}", :name => "print" %>
<%= submit_tag "#{t 'excel'}", :name => "excel" %>
<%= end %>
headers_search
指向application.js
$.fn.ajaxFilter = function() {
this.submit(function() {
$.get(this.action, $(this).serialize(), null, "script");
return false;
});
}
$("#headers_search").ajaxFilter();
所以,我对我做错的地方感到困惑..我有点像rails新手。谢谢