Change CSV name in Rails without respond_to block -


i have button allows users download csv in rails 3.2 app.

view

<%= link_to "export registration data", learn_registrants_path(format: "csv", :id => @event.id), :class => "btn btn-default btn-primary" %> 

controller

 def export_registrants     @event = event.find(params[:id])     if current_learner.id == @event.registration_contact_id       registrants = eventregistration.includes.where(event_id: @event.id)       csv = registrantsexport.new(registrants).to_csv       render text: csv     end   end 

with code above csv file gets downloaded named learn_registrants.csv. add event_id csv name. found filename: option used in respond block, can't use here. ideas on how can change csv name without refactoring use respond_to block?

you use send_data instead:

send_data csv, :filename => 'your_file_name.csv',      :disposition => 'inline', :type => "multipart/related" 

or can change file name altering header

headers["content-disposition"] = "attachment; filename=\"#{filename}\""  

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -