是否可以让javascript将图像复制到剪贴板?我想要复制Chrome右键/控制点击浏览器中的图像时Chrome所具有的"复制图像"功能.
我见过文本解决方案,一些基于Flash的文本解决方案.但我只对图像数据感兴趣.仅限Chrome.不要关心此要求的IE或FF.
按照此页面上的文档... http://guides.spreecommerce.com/developer/calculators.html
我在模特/狂欢/计算器/中创建了一个类
module Spree
class Calculator::ZipTax < Calculator
def self.description
"Calculates Tax Rates From Zipcode in TaxRates Table"
end
def compute(computable)
case computable
when Spree::Order
compute_order(computable)
when Spree::LineItem
compute_line_item(computable)
end
end
def compute_order(order)
zipcode = order.bill_address.zipcode[0,5]
zip = TaxTable.where(:zipcode => zipcode).first
if(zip.present?)
rate = zip.combined_rate
order.line_items.sum(&:total) * rate
else
0
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
在initializers/spree.rb中我添加了:
config = Rails.application.config
config.spree.calculators.tax_rates << Spree::Calculator::ZipTax
Run Code Online (Sandbox Code Playgroud)
但我不能让Rails开始.我在initializer/spree.rb文件中得到nil:NilClass(NoMethodError)的未定义方法`<<'.
如何注册自定义计算器?使用Spree 1.3.2.
生成一些json有困难.我试图将一个活动记录结果呈现给json,如下所示:
@data = User.find(1)
respond_with(@data, :include => :status)
Run Code Online (Sandbox Code Playgroud)
json的结果是:
{
-user: {
address: null
email: "test@email.com"
first_name: "Test"
last_name: "Man"
status_id: 1
username: "testguy"
status: { }
}
}
Run Code Online (Sandbox Code Playgroud)
所以有什么问题?问题是:include =>:status似乎没有带来关系.在我的用户模型中,我有一个belongs_to:status.如何让这个在单个结果集上工作?
当我这样做:
@data = User.where("id = 1")
respond_with(@data, :include => :status)
Run Code Online (Sandbox Code Playgroud)
这种关系在json结果集中表现得很好.但它在一个对象数组中,我不想要.
有任何想法吗?
activerecord ×1
clipboard ×1
copy-paste ×1
html5 ×1
javascript ×1
json ×1
respond-with ×1
spree ×1