ruby on rails - export data to csv without changing pages -
what proper way export data csv file rails.
i have "export" link in views
shows.html.erb
<%= link_to "csv", patient_record_path(format: "csv") %> patient_record_controller
def show .... respond_to |format| format.html format.csv { send_data restclient.get(url, :accept => :csv), :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; filename=data.csv" } end end when click export error
template missing missing template patient_record/show, application/show {:locale=>[:en], :formats=>[:csv], :handlers=>[:erb, :builder, :coffee]}. searched in: * "/rubymineprojects/my_app/app/views" it redirected url
http://www.host.com/patient_record/1.csv i shouldnt redirecting pages, want export csv file , keep on same page
if use ajax, functionality works fine, file doesn't show being downloaded in broser
you doing request 'show' , throwing error because looking show.html.erb file within patients records controller. possible avoid page redirecting if used jquery + ajax issue request doing this:
$('#export_link).on ("click", function(e) { e.preventdefault(); $.ajax({ url: whatever_the_patient_record_path_is, etc........ }); });
Comments
Post a Comment