Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails link_to :format => :xlsx not generating link to .xlsx path

If I hit this url: http://localhost:3000/reports/action.xlsx it shows a generated xlsx file.

If I have a link_to like this:

<%= link_to 'Export to Excel', reports_affirmative_action_path, :format => :xlsx %>

It generates a link to this page: http://localhost:3000/reports/action

Why does my link_to with :format => :xlsx not link to the correct path?

like image 957
Catfish Avatar asked Apr 16 '13 17:04

Catfish


1 Answers

Your link_to and path are slightly off. You want

<%= link_to('Export to Excel', reports_affirmative_action_path(format: :xlsx)) %>

Where the format is an argument to the path helper, not link_to.

like image 190
Sandy Vanderbleek Avatar answered Oct 19 '22 10:10

Sandy Vanderbleek