- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在使用 Refile 和 Rails 4。我正在按照他们的教程进行 multiple image upload .每个帖子可以有多个图像。我的模型看起来像这样:
后.rb:
has_many :images, dependent: :destroy
accepts_attachments_for :images, attachment: :file
图片.rb:
belongs_to :post
attachment :file
我可以上传文件,使用:
<%= f.attachment_field :images_files, multiple: true, direct: true, presigned: true %>
但是当我尝试检索像这样的图像时:
<%= attachment_image_tag(@post.images, :file, :small) %>
我得到错误:
undefined method file for #<Image::ActiveRecord_Associations_CollectionProxy:0x007fbaf51e8ea0>
如何使用多张图片上传来检索带有 refile 的图片?
最佳答案
为了检索属于帖子的图像,您需要遍历图像数组。
<% @post.images.each do |image| %>
<%= attachment_image_tag(image, :file, :fill, 300, 300) %>
<% end %>
助手 attachment_image_tag
采取:
所以在这里,@posts.images
包含一个 image
对象数组。就是那个有附件的对象。
class Image < ActiveRecord::Base
belongs_to :post
attachment :file
end
然后,当您迭代 images
时,您将 image 对象
和附件列的名称提供给助手,此处为 :file
.
关于ruby-on-rails - 重新归档 gem : multiple file uploads,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31226156/
我正在阅读许多 plist 并将它们显示在 UITableview 中。问题是,应用程序本身非常慢,我确实阅读了一些有关归档或序列化的内容,归档是否会使应用程序更快,或者如果我想使用大量数据,我应该尝
我用谷歌搜索并搜索了 SO,但没有直接的结果。看来我对 Apple 文档中的以下内容存在根本性的误解: An archive can store an arbitrarily complex obje
刚开始学习 iOS,我有一个非常基本的问题:归档/取消归档整个对象集合的正确方法是什么? 我了解到您首先需要在类上实现 NSCoder 协议(protocol)。假设我有一个可以正确归档和取消归档的类
所以这是我的问题。我正在尝试归档一个对象数组,当我取消归档它们时,尽管计数相同并且根对象内的对象相同,但它在未归档的数组中找不到指定的对象。 -(void)tableView:(UITableView
我需要归档一个由 ArrayController 控制的 NSMutableArray。我试过这个: [NSKeyedArchiver archivedDataWithRootObject:array
我想存档只包含 NSString 的字典,但是当我取消存档时,发生错误: [NSKeyedUnarchiver initForReadingWithData:]: non-keyed archive
我想存档每个构建的构建日志,例如到数据库。我知道如何归档工件,但我没有在构建日志中看到任何明显的内容。 最佳答案 我想您需要在归档之前结束您的工作。以下是一个 Groovy 脚本,它使用不同的方法来获
因此,我正在尝试将我的 iPhone 应用程序存档以进行临时测试,但我遇到了一些奇怪的情况。当我归档它时,在它显示归档类型的顶部,由于某种原因,它显示“Mac 应用程序归档”而不是通常的“iOS 应用
我正在使用 java Spring 和 spring data for mongodb。 我有一个集合,需要仅包含过去 3 个月的文档,但所有文档都应以某种方式保存(也许导出到文件?)。我正在寻找解决
我的应用程序使用了一个我插入的附加项目,我链接它然后使用以下代码导入它: #import 如果我正常运行应用程序,应用程序工作正常,但如果我按下存档按钮,上面报告的代码行就会出错。它说:找不到 SB
我有多个表。如表 1、表 2、表 3 等 需要什么: 1. 从表 1 中获取特定行。 (例如:id = 203) 2. 从 table2 中获取与 id 203 相关的所有值(例如:1,2,3,4,5
我正在尝试使用 Xcode 4.3.2 将我的应用存档到一个 .ipa 文件中以发送到应用商店,但在尝试存档时出现此错误: 'KKGridView/KKGridView.h' file not fou
这个问题在这里已经有了答案: Find and xargs to correctly handle filenames with spaces in their names (3 个答案) 关闭 3
我正在创建一个在线订单系统,用于定期销售商品(蔬菜盒送货上门)。我有一个“订单”模型(简化)如下: class BoxOrder(models.Model): customer = model
我已经检查过我的应用程序产品大小约为 10MB,但是当我构建它进行归档时,它显示 Appstore 大小为 20MB,即它几乎翻了一番。但是当我在文件夹中看到存档时,它的大小仍然是 10MB,我不知道
我使用的是 Mercurial 1.7.2。在 Windows 上,我想提取指定更改集中的所有文件(在我的案例提示中)。这样我就可以只将我已更改的文件上传到我的网络服务器。 如果我想获取整个存储库的未
我正在为使用 iOS 6 的 iPad 项目开发 Objective-C 代码库。 在我将类“ClassA”的名称重构为“ClassB”之后,我发现以下测试失败了: NSData *encodedOb
我的 Xcode 项目能够在模拟器上成功构建和运行,但是当我尝试将其存档时出现一个问题,提示该项目无法导入桥接 header 。 这是在模拟器上运行的图像应用。 现在,当我尝试将其存档到通用 IOS
我是 IOS 新手。我已经开发了一个 IOS 应用程序,现在我想在 iTunes 上发布这个应用程序。我已经创建了证书、应用程序 ID,然后是临时配置文件。我已成功将此添加到“build设置”的“代码
我有一个文件,其中包含我想用 tar 归档的文件列表。我们称之为 mylist.txt 它包含: file1.txt file2.txt ... file10.txt 有没有办法可以发出以 mylis
我是一名优秀的程序员,十分优秀!