I have a form to showing a report, but I need 3 features which is print to pdf
, print to excel
, and also showing preview via html itself using js
This is the first condition that only for pdf
and excel
and work well for both.
controller:
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
view:
<%= form_tag(models_path, :method => "get") do %>
<%= submit_tag "#{t 'pdf'}", :name => "print" %>
<%= submit_tag "#{t 'excel'}", :name => "excel" %>
<% end %>
But when I start adding preview feature through js
, it not error, but both submit button (pdf n excel) pointing to js.
new controller
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
new view
<%= 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
is pointing on application.js
$.fn.ajaxFilter = function() {
this.submit(function() {
$.get(this.action, $(this).serialize(), null, "script");
return false;
});
}
$("#headers_search").ajaxFilter();
So, I confuse on where I did mistake.. I'm kind of rails newbie. Thanks