I am having trouble downloading files from rails applications. If someone can give me some insight on what I am missing and doing wrong, I would greatly appreciate it. Also, I have been reading up on send_data
and send_file
. I do not understand what it means when asking to send DATA for send_data
, while PATH for send_file
. What's the difference? Thanks again!
routes.rb
resources :companies do
member do
get 'send_document'
end
end
view code (in static_pages_controller, not companies_controller)
<ul>
<% @companies.each do |company| %>
<li>
<%= company.compName %>
<%= company.formType %>
<%= company.fileLocation %>
<%= link_to "View Document", controller: :companies, send_document_path(company), , method: :get %>
</li>
<% end %>
</ul>
companies_controller.rb
def send_document
@company = Company.find(params[:id])
send_file "#{@company.fileLocation}"
end
Error: I am receiving an error on the link_to line. I am having trouble trying to download a file with specific companies in my database. Any help is appreciated. Thanks! Also, in the companies_controller, the code Company.find(params[:id]) is saying it is without a company id.
UPDATE: I changed the code to be
<%= link_to "View Document", send_document_path(company), {controller: :companies}, method: :get %>
and am now receiving this error:
app/views/layouts/_search_bar.html.erb where line #6 raised:
undefined method `send_document_path' for #<#<Class:0x00000005446998>:0x00000004147360>
Extracted source (around line #6):
3
4
5
6<%= link_to "View Document", send_document_path(company), {controller: :companies}, method: :get %>
7
8
9
Any help would be appreciated! Thanks!