English 中文(简体)
从目录链接文件
原标题:Rails Linking Files from Directory

RUBY -v 1.8.7,铁路 -v 2.3.8

我试图将公共/数据文件与视图连接起来,这让我头痛。我知道我应该可以自己做这件事,但我失去了旧的铁路手册,从亚马逊订购了一本新书,一周内就会到。

我读过上传文件的教程

My issue: I have about 3000 folders; each folder has about 3~5 files that go with it.

我的问题:

  • 我应该建立一个 db 迁移程序, 以便跟踪文件的地址吗? 这样它就可以方便地访问吗? ( 即 命令. data_ file. address; 我猜是的 )

  • 一旦文件被上传, 我如何链接文件, 这样文件会被正确链接到视图 。

所以无论如何,我得到了这个下来:

<% @files = Dir.glob("public/data/*") %>
<% for m in @files %>
<% new_file = m.to_s %>
<li><%= link_to m.to_s, new_file %> </li>
<% end %>

与文件的链接最后为: localhost:30:300/public/ data/temp.pdf

但是这不管用,

 No route matches "/public/data/temp.pdf" with {:method=>:get}

我想我需要一些东西 在路线. rb 使它的工作......

 map.datafile  #{RAILRS_ROOT}/public/data/:id , :controller =>  upload 

感谢任何帮助或建议。

问题回答

不需要特殊的地图,资源路径 不需要特殊的控制器方法发送到

只要略去公共部分, 校正链接, 它就起作用了。 我从另一个问题里用这个代码 。

    <% Dir["public/files/*.pdf"].each do |file| %>
    <li><%= link_to  Letter , file[//.*/] %></li>
    <% end %>




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签