Override the respond_to format with form button in rails 3

后端 未结 1 1648
感情败类
感情败类 2021-01-18 15:00

I have a set of reports that are displayed in various formats using the Rails call \"respond_to\", such that if the URL ends in CSV or JSON, the report is generated in that

相关标签:
1条回答
  • 2021-01-18 15:45

    I can finally respond to my own question, now. So here's the answer:

    I figured out how this can be accomplished. You can set the name of the buttons to be "format" and set the value to the extension that you would append to the URL.

     <%= button_tag( 'HTML', :value => 'html', :name => 'format' ) %>
     <%= button_tag( 'CSV', :value => 'csv', :name => 'format' ) %>
     <%= button_tag( 'JSON', :value => 'json', :name => 'format' ) %> 
    

    Simply changing the params[:format] doesn't work. You have to pass it in before your action runs.

    0 讨论(0)
提交回复
热议问题