我创建了一个gem,由于某种原因,这个一直在烦我,并拒绝通过bundler正确安装.
这是Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.9'
gem "switch_access-rails", "~> 1.1.6"
Run Code Online (Sandbox Code Playgroud)
捆绑安装失败:
Could not find gem 'switch_access-rails (~> 1.1.6) ruby' in the gems available on this machine.
Run Code Online (Sandbox Code Playgroud)
这有效:
gem install switch_access-rails -v 1.1.6
Run Code Online (Sandbox Code Playgroud)
宝石出现在rubygems上:https://rubygems.org/gems/switch_access-rails/versions/1.1.6
我甚至尝试从1.1.5版本升级到1.1.6,看看是否有帮助.
安装版本1.1.4 in bundle install工作.
有关从哪里开始查看/调试捆绑安装的提示?
使用AWS SDK gem,我可以轻松获取给定一些参数的对象URL.
例:
credentials = Aws::Credentials.new(ENV['S3_KEY'], ENV['S3_SECRET'])
s3 = Aws::S3::Resource.new(
credentials: credentials,
region: ENV['S3_REGION_KEY']
)
object = s3.bucket('my-bucket').object('path/to/file.ext')
url = object.public_url
Run Code Online (Sandbox Code Playgroud)
给定一个公共URL,我可以将其反转以获得一个Aws::S3::Object?是否有使用此SDK的方法?或者我应该手动拆分URL?(我宁愿避免这种情况.)
如何CAP_PROP_FRAME_COUNT从python中的opencv 访问?我试过这个:
import cv2
cap = cv2.VideoCapture('myvideo.avi')
frames_count, fps, width, height = cap.get(cv2.CAP_PROP_FRAME_COUNT), cap.get(cv2.CAP_PROP_FPS), cap.get(cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
Run Code Online (Sandbox Code Playgroud)
还有这个:
import cv2
import cv
cap = cv2.VideoCapture('myvideo.avi')
frames_count, fps, width, height = cap.get(cv.CAP_PROP_FRAME_COUNT), cap.get(cv.CAP_PROP_FPS), cap.get(cv.CAP_PROP_FRAME_WIDTH), cap.get(cv.CAP_PROP_FRAME_HEIGHT)
Run Code Online (Sandbox Code Playgroud)
还有这个:
import cv2
cap = cv2.VideoCapture('myvideo.avi')
frames_count, fps, width, height = cap.get(cv2.cv.CAP_PROP_FRAME_COUNT), cap.get(cv2.cv.CAP_PROP_FPS), cap.get(cv2.cv.CAP_PROP_FRAME_WIDTH), cap.get(cv2.cv.CAP_PROP_FRAME_HEIGHT)
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
AttributeError: 'module' object has no attribute 'CAP_PROP_FRAME_COUNT'
Run Code Online (Sandbox Code Playgroud)
我正在使用python 2.7.5和OpenCV 2.4.9.
我正在使用Rails 4.2.我有3个这样的表:
class Collection < ActiveRecord::Base
has_many :shares
has_many :images, through: :shares
has_many :latest_images, -> { order(created_at: :desc).limit(10) }, class_name: 'Image', through: :shares, source: :image
end
class Share < ActiveRecord::Base
belongs_to :image
belongs_to :collection
end
class Image < ActiveRecord::Base
has_many :shares
has_many :collections, through: :shares
end
Run Code Online (Sandbox Code Playgroud)
我的目标是选择一些集合并使用该latest_images关系预加载每个集合的前10张最新卡片.
如果我这样做:
collections = Collection.where(some_condition).includes(:latest_images)
Run Code Online (Sandbox Code Playgroud)
问题是latest_images将包含所有卡,不仅是最后10个(即使有一个limit(10))
collections.first.latest_images.count # => more than 10!!!
Run Code Online (Sandbox Code Playgroud)
相反,如果我limit(10)在加载集合后添加,我将遇到N + 1查询问题:
collections.each { |collection| collection.latest_images.limit(10).do_something } # N+1 QUERY
Run Code Online (Sandbox Code Playgroud)
有解决方案吗
我正在尝试使用 Nokogiri 解析包含自定义 HTML 标记的 HTML 片段。
例子:
string = "<div>hello</div>\n<custom-tag></custom-tag>"
Run Code Online (Sandbox Code Playgroud)
我尝试以多种方式加载它,但没有一种是最佳的。
如果我使用 Nokogiri::HTML:
doc = Nokogiri::HTML(string)
Run Code Online (Sandbox Code Playgroud)
当我使用 时to_html,它会添加一个doctype和一个html包装内容的标签。这是不受欢迎的。
如果我使用 Nokogiri::XML:
doc = Nokogiri::XML(string)
Run Code Online (Sandbox Code Playgroud)
我得到了Error at line 2: Extra content at the end of the document,因为在 XML 中必须有一个包含所有文档内容的根标记。如果我再次尝试保存此内容,则输出为<div>hello</div>(删除第一个之后的每个标签)
我也试过doc = Nokogiri::HTML.fragment:
doc = Nokogiri::HTML.fragment(string)
Run Code Online (Sandbox Code Playgroud)
但它抱怨custom-tag.
如何使用此 HTML 片段使 Nokogiri 正确解析?
我从jQuery源代码中遇到了这个片段(事件处理):
var events = ['click', 'focus', 'blur', …];
jQuery.each(event,function(i,name){
jQuery.prototype[name] = function(fn){
return this.bind(name,fn);
};
});
Run Code Online (Sandbox Code Playgroud)
谁可以给我解释一下这个?this.bind(name,fn);工作怎么样element.addEventListener('event','callback()')?
我知道javascript的基础知识,但我不知道JavaScript的更高级部分.自从我自学了以后,我的JavaScript知识就有很多漏洞.如果有人知道一个好的来源,我可以从中学到更高级的JavaScript,我也希望听到.
谢谢.
我想知道是否有任何方法可以在PHP中使用Parser从这个站点获取值https://btc-e.com/api/2/btc_usd/ticker并将它们设置为php代码中的变量?
我已经看了一下php解析器,我发现的唯一的东西就是回显网站上所有信息的解析器.
rails 4 中是否有等效的update_columnsforhstore属性?
我的模型是:
class Image < ActiveRecord::Base
store_accessor :additions, :small, :medium, :big, :image_version
end
Run Code Online (Sandbox Code Playgroud)
假设我想更新small.
我试过:
@image = Image.first
@image.update_columns(small: 'my_small_image')
Run Code Online (Sandbox Code Playgroud)
但我当然收到:
PG::UndefinedColumn: ERROR: column "small" of relation "contents" does not exist
LINE 1: UPDATE "images" SET "small" = 'my_small_image' WHERE "imag...
^
: UPDATE "images" SET "small" = 'my_small_image' WHERE "images"."id" = 1
Run Code Online (Sandbox Code Playgroud)
有没有简单的方法来做到这一点?
编辑:我不能使用update_attributes,因为我只需要保存传递的参数。
update_attributes调用save,我不想要这个,因为它保存了所有其他更改的属性,而不仅仅是通过的属性。
例子:
@image = Image.first
@image.big = 'fjdiosjfoa'
@image.update_attributes(small: 'my_small_image') …Run Code Online (Sandbox Code Playgroud) 我有一个bootstrap模式,在其中,我有一个用于标记的ui-select.这是我的例子:
<div class="modal modal-invite">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<ui-select multiple tagging tagging-label="" ng-model="email_list" theme="bootstrap" ng-disabled="disabled" on-select="" on-remove="" title="Insert your friends email here." >
<ui-select-match placeholder="Your friends email here...">{{$item}}</ui-select-match>
<ui-select-choices repeat="email in email_list | filter:$select.search">
{{email}}
</ui-select-choices>
</ui-select>
</div>
<div class="modal-footer">
<button class="btn btn-success">Invite</button>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的问题是:当我打开模态时$('modal-invite').modal('show'),占位符(和可点击区域)的大小是10像素,如下所示:


点击它后,它获得正确的宽度.
当模态打开时,如何使ui-select刷新它的大小?
我在轨道4.1.9上使用ruby.
有没有办法定义应该随时重新编译的文件白名单,即使它们没有改变?
例如:我有几个.js.erb文件注入了一些Rails变量.因此,即使原始文件没有更改,也需要重新编译.