我有一个 rails 3 应用程序,今天我决定在创建操作中将 resque 添加到我的控制器中的 message_image 上传器
def create
@recipient = User.find(params[:message][:recipient_id])
@message = current_user.send_message(@recipient, params[:message][:body])
#@message.images << MessageImage.create!(params[:message][:images_attributes])
respond_with(@message) do |format|
if @message.save!
Resque.enqueue(AddImageToMessage, @message.id, params[:message][:images_attributes])
format.js do
unless request.referer.include? 'messages'
render :text => "window.location = '#{messages_path}'", notice: 'message has been succ created.'
end
end
else
redirect_to :back
end
end
结束,我有课
class AddImageToMessage
@queue = :messages_queue
def self.perform(message_id, images_params)
message = Message.find(message_id)
message.images << MessageImage.create!(images_params)
message.save
end
end
但是,如果我尝试创建新消息并附加图像,redis 日志服务器中会出现错误 https://gist.github.com/Olefine/6270753。在此日志中,我的记录无效,但我所有的验证都通过了如果我在控制器中使用标准方法
@message.images << MessageImage.create!(params[:message][:images_attributes])