我通过jquery-fileupload-rails gem 在Rails 3.2应用程序中使用blueimp jquery-file-upload.
我正在尝试在上传之前在客户端调整图像大小,但是在访问文档时遇到了问题.我的代码如下.目前上传效果很好,但图片没有调整大小.
通过jquery-file-upload调整图像大小的正确语法是什么.
(基于此和本文档的coffeescript中显示了两种方法.对我来说都不适用.)
#Coffeescript
jQuery ->
if $("#new_asset").length
$("#new_asset").fileupload
dataType: "script"
add: (e, data) ->
types = /(\.|\/)(jpe?g|png)$/i
file = data.files[0]
if types.test(file.type) || types.test(file.name)
data.context = $(tmpl("template-upload", file))
$('#progress-container').append(data.context)
jqXHR = data.submit()
$("button.cancel").click (e) ->
jqXHR.abort()
else
alert("#{file.name} is not a jpeg or png image file")
progress: (e, data) ->
if data.context
progress = parseInt(data.loaded / data.total * 100, 10)
data.context.find('.bar').css('width', progress + '%')
stop: (e, data) …Run Code Online (Sandbox Code Playgroud) ruby-on-rails blueimp jquery-file-upload jquery-fileupload-rails
我有一个主模型,可以为不同公司的不同类型的凭证自动创建字母数字。如何更新主模型。型号:
class VoucherTypeMaster(models.Model):
code = models.CharField(max_length=12,null=True,blank=True)
description = models.CharField(max_length=30,null=True,blank=True)
last_number = models.IntegerField(null=True,blank=True)
company = models.ForeignKey(Company,
related_name='voucher_master_company')
class Meta:
unique_together = ('code','company')
class Voucher(models.Model):
type = models.ForeignKey(VoucherTypeMaster)
date = models.DateField(default=datetime.datetime.now().date())
company = models.ForeignKey(Company,
related_name='voucher_company')
number = models.CharField(max_length=20,null=True,blank=True)
narration = models.CharField(max_length=30,null=True,blank=True)
amount = models.DecimalField(decimal_places=2,max_digits=9)
# class Meta:
# unique_together = ('company','number','date')
def __unicode__(self):
return '%s - %s' %(self.number,self.narration)
def save(self, *args, **kwargs):
try:
voucher_type = VoucherTypeMaster.objects.get(
company=self.company,
code=self.type.code
)
voucher_type.last_number += 1
voucher_type.save()
self.number = voucher_type.last_number
# self.type.save() # throws exception
except …Run Code Online (Sandbox Code Playgroud)