我想替换我的XHTML文档中所有段落中的inner_text.
我知道我可以像这样得到Nokogiri的所有文字
doc.xpath("//text()")
Run Code Online (Sandbox Code Playgroud)
但是我只希望对段落中的文本进行操作,如何在不影响链接中最终存在的锚文本的情况下选择段落中的所有文本?
#For example : <p>some text <a href="/">This should not be changed</a> another one</p>
Run Code Online (Sandbox Code Playgroud) 我如何优化我的SQL查询,忽略这样的情况:
Meeting.find(5).users.size => SELECT COUNT(*)FROM ... WHERE ...
User.find(123).meetings.size => SELECT COUNT(*)FROm ... WHERE ...
我不知道如何在这里使用counter_cache.
这是我的模型关系:
class Meeting < ActiveRecord::Base
has_many :meeting_users
has_many :users, :through => meeting_users
end
class User < ActiveRecord::Base
has_many :meeting_users
has_many :meetings, :through => meeting_users
end
class Meeting_user < ActiveRecord::Base
belongs_to :meeting
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
什么是最优解决方案?
如何在这里实现counter_cache?
我有一个很大的视图,需要很长时间才能完成呈现内容.如何分析最佳方法,视图的哪一部分花费最多时间?我已经阅读了关于ruby-prof的内容,但我不确定,在哪里放入它来分析视图渲染.如果存在其他选项,我也想知道它们.
<% semantic_form_for(@product, :html => {:multipart => true}) do |f| %>
<% f.inputs do %>
<%= f.input :name %>
<%= f.input :price %>
<%= f.input :pno %>
<%= f.input :description %>
<%= f.input :shop_category %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
产品属于Shop_category,Shop_category属于Shop.
如何更改线路:
<%= f.input :shop_category %>
Run Code Online (Sandbox Code Playgroud)
要仅显示属于具有id的商店的shop_categories,例如15,而不是在选择框中显示所有shop_categories?
如何在新安装的Emacs 23.2(Debian发行版)中使用Emacs Code Browser v2.40
在我的init.el中,我有:
(semantic-mode)
(add-to-list 'load-path
"~/.emacs.d/plugins/ecb-2.40")
(require 'ecb)
Run Code Online (Sandbox Code Playgroud)
当我运行Emacs时,我在statrup上收到一条错误消息:
文件错误:无法打开加载文件,semantic-ctxt
我读过CEDET套件是从Emacs 23开始构建的,所以我没有安装它.
<li>
<select id="foo"></select>
</li>
<li>
<select id="bar"></select>
</li>
<li>
<select id="baz"></select>
</li>
var select_after = function(src){
//How get all select elements after the one specified as argument ?
}
Run Code Online (Sandbox Code Playgroud)
怎么写这个方法?
select_after($("#foo"))
Run Code Online (Sandbox Code Playgroud)
应返回数组中的#bar和#baz元素
select_after($("#bar"))
Run Code Online (Sandbox Code Playgroud)
应该在数组中返回#baz元素
select_after($("#baz"))
Run Code Online (Sandbox Code Playgroud)
应该返回空数组
我应该怎么写这个方法?
我在使用DigitalOcean Droplet编译Ruby时遇到问题.
rbenv 0.4.0-97-gfe0b243
Ubuntu 14.04 LTS
Linux bashman 3.13.0-24-generic#46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
rbenv install 2.1.1
Run Code Online (Sandbox Code Playgroud)
给我:https://gist.github.com/astropanic/e4d3a3602612b3c21636
失败似乎与:
compiling readline.c
readline.c: In function ‘Init_readline’:
readline.c:1977:26: error: ‘Function’ undeclared (first use in this function)
rl_pre_input_hook = (Function *)readline_pre_input_hook;
^
readline.c:1977:26: note: each undeclared identifier is reported only once for each function it appears in
readline.c:1977:36: error: expected expression before ‘)’ token
rl_pre_input_hook = (Function *)readline_pre_input_hook;
^
readline.c: At top level: …Run Code Online (Sandbox Code Playgroud) 什么是最好的(从性能的角度来看)在Git中找到更改某个文件的最后10个用户的方法?
例如,我想知道文件foo.txt的最后10个提交者(不是最后10个提交)
我有一个FB应用程序,当我作为取消授权回调URL输入我的开发框地址时,在FB上移除应用程序后,该框被用来请求此框:
POST /facebook/deauthorize HTTP/1.1
Host: bashman.org
Accept: */*
Content-Length: 261
Content-Type: application/x-www-form-urlencoded
Connection: close
fb_sig_uninstall=1&fb_sig_locale=de_DE&fb_sig_in_new_facebook=1&fb_sig_time=1322732591.2685&fb_sig_added=0&fb_sig_user=1476224117&fb_sig_country=de&fb_sig_api_key=e39a74891fd234bb2575bab75e8f&fb_sig_app_id=32352348363&fb_sig=f6bbb27324aedf337e5f0059c4971
Run Code Online (Sandbox Code Playgroud)
(这里的钥匙是假的)
但!当我在取消授权回调URL中输入我的生产箱URL时,永远不会发出POST请求.用Tcpdump测试它.我的生产机器没有要求,为什么?
我用mtr检查了从我的生产箱到请求来自的IP地址的路由,一切正常,丢失了0%的数据包.
主机名端口和路径是正确的,测试了1k次,没有防火墙,IDS或其他系统阻塞我的以太网插槽.
为什么没有调用Post回调?(我该如何解决?)
我如何调试这个以确定问题是什么?