我的应用程序将图像存储在S3上,然后通过Cloudfront代理它们.我很高兴使用新的S3 CORS支持,以便我可以使用HTML5 canvas方法(具有跨源策略),但似乎无法正确配置我的S3和Cloudfront.当我尝试将图像转换为canvas元素时,仍然遇到"Uncaught Error:SECURITY_ERR:DOM Exception 18".
这是我到目前为止所拥有的:
S3
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>MY_WEBSITE_URL</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>MY_CLOUDFRONT_URL</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)
CloudFront的
起源
Origin Protocol Policy: Match Viewer
HTTP Port: 80
HTTPS Port: 443
Run Code Online (Sandbox Code Playgroud)
行为
Origin: MY_WEBSITE_URL
Object Caching: Use Origin Cache Headers
Forward Cookies: None
Forward Query Strings: Yes
Run Code Online (Sandbox Code Playgroud)
这里有什么我想念的吗?
更新:刚尝试将标题更改为
<AllowedHeader>Content-*</AllowedHeader>
<AllowedHeader>Host</AllowedHeader>
Run Code Online (Sandbox Code Playgroud)
基于这个问题的Amazon S3 CORS(跨域资源共享)和Firefox跨域字体加载
仍然没有去.
更新:更多信息请求
Request
URL:https://d1r5nr1emc2xy5.cloudfront.net/uploaded/BAhbBlsHOgZmSSImMjAxMi8wOS8xMC8xOC81NC80Mi85NC9ncmFzczMuanBnBjoGRVQ/32c0cee8
Request Method:GET
Status Code:200 OK (from cache)
Run Code Online (Sandbox Code Playgroud)
UPDATE
我想也许我的请求不正确,所以我尝试启用CORS
img.crossOrigin = '';
Run Code Online (Sandbox Code Playgroud)
但然后图像没有加载,我得到错误:跨源资源共享策略拒绝跨源图像加载.
我正在使用"where"语法编写Rails 3 ActiveRecord查询,该语法使用SQL IN和SQL OR运算符,并且无法弄清楚如何将它们一起使用.
此代码有效(在我的用户模型中):
Question.where(:user_id => self.friends.ids)
#note: self.friends.ids returns an array of integers
Run Code Online (Sandbox Code Playgroud)
但这段代码
Question.where(:user_id => self.friends.ids OR :target => self.friends.usernames)
Run Code Online (Sandbox Code Playgroud)
返回此错误
syntax error, unexpected tCONSTANT, expecting ')'
...user_id => self.friends.ids OR :target => self.friends.usern...
Run Code Online (Sandbox Code Playgroud)
知道如何在Rails中编写它,或者只是原始SQL查询应该是什么?
我是Mongo DB和Mongoid的新手(并且仍然是Ruby on Rails的新手).由于Ryan Bates没有碰巧有一个Mongoid Railscast,我需要指向其他好的教程/截屏视频.谢谢!
我一直试图围绕javascript函数和范围如何工作,这对我来说没有意义.有人可以解释为什么以下代码输出:'动物说喵'而不是'小猫说喵'?
(function($, exports){
var animal = function(){};
exports.Animal = animal;
})(jQuery, window);
(function($, Animal){
var kitty = new Animal;
kitty.sayHi = function(){
console.log(this);
console.log('says meow');
}
$($.proxy(function(){
$('#js_test').click($.proxy(kitty.sayHi, kitty));
}, kitty))
})(jQuery, Animal);
Run Code Online (Sandbox Code Playgroud)
UPDATE
@FunkyFresh在注释中指出console.log在传递一个对象时调用toString,默认情况下返回对象的类型(animal).当我用上面的代码更新时
animal.prototype.name = 'Mammal';
Run Code Online (Sandbox Code Playgroud)
在顶部的代码块中,和
kitty.name = 'Zax';
Run Code Online (Sandbox Code Playgroud)
在底部,控制台输出'Zax说喵',这似乎是正确的.
我在使用Rails的许多WYSIWYG宝石/插件时遇到了问题,所以我自己使用RedCloth gem构建了一个.我希望用户在填写表单时看到HTML格式文本的实时预览,但不知道如何使用jQuery和RedCloth.这是我在application.js中尝试的:
$('#comment').keyup(function(){
var formatted = RedCloth.new($(this).val()).to_html;
$('#preview').html(formatted);
});
Run Code Online (Sandbox Code Playgroud)
不要惊讶这不起作用,因为RedCloth.new可能无法在.js文件中执行,但不知道如何动态格式化文本.
我正在尝试从我的Rails应用程序进行本地备份,该应用程序部署到Heroku,并遇到问题.我按照这里的说明操作:http://docs.heroku.com/taps并安装了Taps.
我有两种类型的错误.我在本地创建了一个SQLite数据库,并尝试使用此命令提取数据:
(sudo)heroku db:pull sqlite://Users/username/folder/testbackup.db
要么
(sudo)heroku db:pull sqlite:// username:password@localhost/Users/username/folder/testbackup.db
但不管怎样,我得到了这个:
无法连接数据库:Sequel :: DatabaseConnectionError - > SQLite3 :: CantOpenException:无法打开数据库:无法打开数据库文件
或者,我尝试让Taps在我的应用程序中自动检测开发数据库并重写它,尽管这不是我想要的.然后我开始得到如下错误:
/opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:777:in
report_activate_error': RubyGem version error: sequel(3.15.0 not ~> 3.13.0) (Gem::LoadError) from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:211:in激活'from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:1056:in'gem'from/Library /红宝石/宝石/ 1.8 /宝石/水龙头-0.3.10 /斌/架构:4
并最终
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/lib/sqlite3/errors.rb:62:in`check': SQLite3 :: SQLException:PRIMARY KEY必须是唯一的(Sequel :: DatabaseError)
非常感谢,我开始尽快备份这些数据非常重要!
我有一个Rails应用程序,现在是非常标准的:Heroku/PostgreSQL后端,用户直接到我的网站更新数据,没有移动应用程序或任何东西.我们将开始将技术许可给其他公司,因此不同版本的接口存在于company1.mywebsite.com,company2.mywebsite.com等,其中所有这些接口共享同一个数据库.
我想就如何构建这个建议提出一些建议.我是否为company1,company2等创建了一个单独的Rails应用程序(包含大量冗余代码),然后使用API密钥设置每个应用程序以使用其RESTful路由查询我的主应用程序?
任何指向我的教程都会很棒.
我的网站上有一个表单,允许用户在其他用户处发送消息,但我想确保他们不能自己定向消息.
该类具有属性:username和:target_user,我只想设置一个验证,检查以确保在保存任何内容之前这些属性不能具有相同的值.
我认为它看起来像这样:
validates_presence_of :user_id, :username, :target_user, :message, :tag
validate :username != :target_user
Run Code Online (Sandbox Code Playgroud)
但显然不知道Ruby能够正确地做到这一点.
jquery ×2
activerecord ×1
amazon-s3 ×1
api ×1
cors ×1
heroku ×1
javascript ×1
live-preview ×1
mongodb ×1
mongoid ×1
redcloth ×1
rest ×1
ruby ×1
sequel ×1
sql ×1
sqlite ×1
taps ×1
validation ×1