rails won't send_data as file

后端 未结 3 1726
一整个雨季
一整个雨季 2020-12-06 16:57

I\'m having problems with Rails method: send_data

Here\'s my action:

def export
  send_data(current_user.contacts.to_csv,
    type: \'te         


        
相关标签:
3条回答
  • 2020-12-06 17:40

    I figured it out.

    It was turbolinks that was messing it all up. I added data-no-turbolink to the export link and now it works as expected.

    0 讨论(0)
  • 2020-12-06 17:47

    The answers here, are for turbolinks classic. There is a newer notation on newer versions of turbolinks:

    <a href="/" data-turbolinks="false">Disabled</a>
    

    https://github.com/turbolinks/turbolinks#disabling-turbolinks-on-specific-links

    0 讨论(0)
  • 2020-12-06 17:47

    send_data has an option hash, so type, disposition and filename need to be set in a hash:

    def export
      send_data(current_user.contacts.to_csv,
      type: 'text/csv', disposition: 'attachment', filename: 'contacts.csv')
    end
    
    0 讨论(0)
提交回复
热议问题