【发布时间】:2014-09-08 07:18:54
【问题描述】:
我在从 Rails 应用程序下载文件时遇到问题。如果有人能给我一些关于我错过了什么和做错了什么的见解,我将不胜感激。另外,我一直在阅读send_data 和send_file。当要求为send_data 发送数据时,我不明白这意味着什么,而为send_file 发送路径。有什么不同?再次感谢!
routes.rb
resources :companies do
member do
get 'send_document'
end
end
查看代码(在 static_pages_controller 中,而不是 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
错误:我在 link_to 行收到错误。我在尝试下载数据库中特定公司的文件时遇到问题。任何帮助表示赞赏。谢谢!此外,在 Companies_controller 中,代码 Company.find(params[:id]) 表示它没有公司 ID。
更新:我将代码更改为
<%= link_to "View Document", send_document_path(company), {controller: :companies}, method: :get %>
现在收到此错误:
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
任何帮助将不胜感激!谢谢!
【问题讨论】:
-
你能发布错误吗??
-
嗨,加根!感谢回复。我已经用我发现的新错误更新了我的帖子
标签: ruby-on-rails