有人可以告诉我这段代码有什么问题吗...?
我在控制器中有一段代码,它用 IMG 标签替换现有的 HTML。 代码如下:
render :update do |page|
page.replace_html "chart-div", "<img src=\"#{chart.chart_file}\"/>" #chart.chart_file is a path
end
无论出于何种原因,我不断收到以下错误:
ActionController::RoutingError (No route matches "/public/charts/1_WEEKLY_ACTUAL_LINE.jpg" with {:method=>:get}):
我不知道为什么它假设我想路由到某个地方。 看来我必须在开头添加“public”才能正确创建文件,但是我必须删除“public”才能显示图像。 有什么想法吗? 是否有更标准的机制来处理动态创建的图像/项目?
最好的。
注意:请勿使用“上传”插件。 所有文件均由系统创建,没有上传。
I have a section of code in a controller that replaces existing HTML with an IMG tag. The code is as follows:
render :update do |page|
page.replace_html "chart-div", "<img src=\"#{chart.chart_file}\"/>" #chart.chart_file is a path
end
For whatever reason, I keep receiving the following error:
ActionController::RoutingError (No route matches "/public/charts/1_WEEKLY_ACTUAL_LINE.jpg" with {:method=>:get}):
I have NO idea why it's assuming I want to route somewhere. It seems that I must have the "public" on the beginning in order for the file to be properly created, however I must remove "public" in order to display the image. Any thoughts? Is there a more standard mechanism by which to deal with dynamically created images/items?
Best.
NOTE: Please no "upload" plugins. All files are created by the system, there are no uploads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加文件时,您会将其添加到文件系统,其位置为
RAILS_ROOT/public/charts/1_WEEKLY_ACTUAL_LINE.jpg
。当您想要显示该文件时,您需要一个指向该文件的 URL。 存储在
public
目录中的文件可通过其相对于public
目录的路径进行访问。您可以尝试这样的操作:
或者,您可以将 URL 存储在数据库中,然后执行以下操作:
When adding the file, you are adding it to the file system, where it is located at
RAILS_ROOT/public/charts/1_WEEKLY_ACTUAL_LINE.jpg
.When you want to display the file, you need a URL that points at it. Files stored in the
public
directory are accessed by their path relative to thepublic
directory.You might try something like this:
Or, you can store the URL in the database, and do: