考虑一个简单的关联......
class Person
has_many :friends
end
class Friend
belongs_to :person
end
Run Code Online (Sandbox Code Playgroud)
让所有在ARel和/或meta_where中没有朋友的人最简洁的方法是什么?
然后是一个has_many:通过版本
class Person
has_many :contacts
has_many :friends, :through => :contacts, :uniq => true
end
class Friend
has_many :contacts
has_many :people, :through => :contacts, :uniq => true
end
class Contact
belongs_to :friend
belongs_to :person
end
Run Code Online (Sandbox Code Playgroud)
我真的不想使用counter_cache - 而且我从我读过的内容中看起来并不适用于has_many:通过
我不想拉出所有的person.friends记录并在Ruby中循环它们 - 我希望有一个可以与meta_search gem一起使用的查询/范围
我不介意查询的性能成本
离实际的SQL越远越好......
我正在从远程站点提取文本并尝试将其加载到默认使用utf-8的Ruby 1.9/Rails 3应用程序中.
以下是一些违规文字的示例:
Cancer Res; 71(3); 1-11. ©2011 AACR.\n
Run Code Online (Sandbox Code Playgroud)
扩展的版权代码如下所示:
Cancer Res; 71(3); 1-11. \xC2\xA92011 AACR.\n
Run Code Online (Sandbox Code Playgroud)
Ruby告诉我字符串被编码为ASCII-8BIT并且输入我的Rails应用程序让我这样:
incompatible character encodings: ASCII-8BIT and UTF-8
Run Code Online (Sandbox Code Playgroud)
我可以使用此正则表达式删除版权代码
str.gsub(/[\x00-\x7F]/n,'?')
Run Code Online (Sandbox Code Playgroud)
产生这个
Cancer Res; 71(3); 1-11. ??2011 AACR.\n
Run Code Online (Sandbox Code Playgroud)
但是如何在UTF-8中将版权符号(以及其他各种符号,如希腊字母)转换为相同的符号?当然有可能......
我看到使用force_encoding的引用,但这不起作用:
str.force_encoding('utf-8').encode
Run Code Online (Sandbox Code Playgroud)
我意识到还有很多其他人有类似的问题,但我还没有看到一个有效的解决方案.
我想使用自己的jQuery代码拖动div.
当鼠标移动缓慢时,这个关于jsfiddle的例子工作得很好
http://jsfiddle.net/craic/kr7Un/
但是任何快速移动都会将鼠标拉出盒子并且跟踪丢失.
jQuery UI draggable没有这个问题,无论你移动的速度如何,跟踪都很好:http://jqueryui.com/demos/draggable/
但我想推出我自己的简单版本,以便我可以将它与Raphael,按键等集成.我已经看过jQuery UI可拖动的源代码,但对我来说,这是非常难以理解的(800行).
我不认为这是事件冒泡的问题......任何想法?