I would a checkbox that when check will return csv and html if otherwise. I follow this video and got the csv to work http://railscasts.com/episodes/362-exporting-csv-and-excel?autoplay=true
now I have a check_box_tag that is to be submitted with the form. if the check box is checked then it should render the csv.
=form_tag exams_path, method: :get do
=text_field_tag :search, params[:search]
=check_box_tag "csv"
= submit_tag "Search by id", name: nil
Inside the controller it have
...
params[:format] = "csv" if params[:csv]
respond_to do |format|
format.html
format.csv {render text:@exams.to_csv}
end
...
but this does not work.