作为参考,我一直在关注本教程:https://devcenter.heroku.com/articles/paperclip-s3除了我现在在localhost测试中,所以我安装了Figaro gem并将我的S3信息放在application.yml中.
使用Rails v4,Cocaine v0.5.3和Paperclip v4.1.0(不确定是否需要提及任何其他gem版本号).
我有一个名为SubmissionDetails的模型,其new.html.erb中我试图将jpg上传到名为attachment的列.以下是相关的型号代码:
has_attached_file :attachment, styles: {
thumb: '200x200>',
large: '800x800>'
}
validates_attachment_content_type :attachment, content_type: /\Aimage\/.*\Z/
Run Code Online (Sandbox Code Playgroud)
当我尝试上传jpg时,它返回到表单,并显示以下错误消息:
1 error prohibited this submission_detail from being saved:
Attachment translation missing:
en.activerecord.errors.models.submission_detail.attributes.attachment.spoofed_media_type
Run Code Online (Sandbox Code Playgroud)
我理解了一些错误,我的en.yml文件中缺少显示此错误消息的文本,但那个欺骗媒体类型部分呢?
这显示在我的服务器控制台中,不确定这是否相关:
[paperclip] Content Type Spoof: Filename header.jpg (["image/jpeg"]), content type discovered from file command: . See documentation to allow this combination.
(0.0ms) rollback transaction
Run Code Online (Sandbox Code Playgroud) 在Rails 4.我最近为我的开发环境安装了bullet gem来清理我的应用程序的N + 1查询.相关型号:
提交内容:属于类别和用户.有很多SubmissionDetails.
用户:有很多提交
分类:有很多提交.属于奖项.
奖项:有很多类别(和类别提交)
提交详细信息:属于提交内容
在我提交的索引页面中,我有一个each do声明来显示当前用户提交的每个提交.
<% current_user.submissions.order('created_at DESC').in_groups_of(3, false) do |group| %>
<div class="row">
<% group.each do |submission| %>
Run Code Online (Sandbox Code Playgroud)
之后,我列出了有关提交的信息,包括其相关类别,奖励和提交详细信息.Bullet说这个陈述我有N + 1个问题:
N+1 Query detected Submission => [:category] Add to your finder: :include => [:category]
N+1 Query detected Submission => [:user] Add to your finder: :include => [:user]
N+1 Query detected Submission => [:submission_details] Add to your finder: :include => [:submission_details]
Run Code Online (Sandbox Code Playgroud)
每次我尝试添加.includes所有这三个模型时,它只选择我列出的第一个(这并不奇怪).我想我需要在涉及多个模型时采用不同的路径 - 也许是连接语句? …
我有两个模型,Submission(父母)和SubmissionDetail(孩子)。Submission有一个名为 的字段status,该字段可以是“未完成”、“待定”、“已批准”或“已拒绝”。当您创建新的 时Submission,status会自动设置为不完整。孩子的外键为:submission_id.
我希望发生的是,当SubmissionDetail创建新的时,其父级的状态将自动更改为“待处理”。不知道该怎么做。例如,我touch在模型中读过一些内容,但我认为这不适用于此处。