我正在使用许多jQuery插件,它经常创建没有id或其他标识属性的DOM元素,并且在Capybara中获取它们的唯一方法(例如用于点击) - 是为了让他们的邻居(其祖先的另一个孩子)首先.但我没有找到任何地方,例如Capybara支持这样的事情:
find('#some_button').parent.fill_in "Name:", :with => name
Run Code Online (Sandbox Code Playgroud)
?
可能这样的问题不是新的,但我没有发现任何类似的东西.我有这样的jQuery代码:
$.ajax({
url : ('/people/'+id),
type : 'DELETE',
dataType : 'json',
success : function(e) {
table.getItems(currentPage);
}
});
Run Code Online (Sandbox Code Playgroud)
我的Rails控制器看起来像这样:
def destroy
@person = Person.find(params[:id])
@person.destroy
respond_to do |format|
format.html { redirect_to(people_url) }
format.json { render :json => @person, :status => :ok }
end
end
Run Code Online (Sandbox Code Playgroud)
这很有效.
但是当我使用以下内容(由标准生成)时,success
不会调用回调:
def destroy
@person = Person.find(params[:id])
@person.destroy
respond_to do |format|
format.html { redirect_to(people_url) }
format.json { head :ok }
end
end
Run Code Online (Sandbox Code Playgroud)
测试下rails 3.0.3
,jQuery 1.4.2
和Firefox 3.6.13
.
Firebug说,在这两种情况下都会触发查询并返回200 OK,在这两种情况下都会删除项目.但在第二种情况下,不会调用回调. …
我在我的routes.rb中有以下内容:
resources :users, :except => [:new, :create] do
get 'friends', :as => :friends, :on => :member, :to => "users#friends"
end
Run Code Online (Sandbox Code Playgroud)
并在我的user.rb中关注:
def to_param
self.login
end
Run Code Online (Sandbox Code Playgroud)
例如,当登录点上的用户(例如'any.thing')来自facebook时,rails会发出路由错误(没有找到路由,我想这是因为它将点后面的任何内容识别为格式或因为路径限制).我怎么能克服这个错误?
我需要有关DRYing视图代码的最佳实践的建议.我的应用程序中有三个类(NewsItem,RssItem和BlogItem),它们使用不同的视图,但其中包含类似的部分.其中一个部分是这样的:
<% if current_user %>
<footer>
<%= marks_bar(@item) %>
<%= favorite_button(@item, "blog_item") || delete_from_favorite_button(@item, "blog_item") %>
<%= share_button(@item) %>
<% if current_user.is_mine?(@item) %>
<div><%= link_to "Edit", edit_user_blog_item_path(current_user, @item) %></div>
<% end %>
</footer>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这三个班级几乎相同,所以我决定把它带到一个不同的地方.在这里我很困惑:我应该使用部分或辅助方法吗?我知道帮助程序主要用于从HTML中分离ruby代码,但在这种情况下,帮助程序将如下所示:
def toolbar_for(item, type_str, edit_path)
if current_user
content_tag(:footer) do |b|
marks_bar(item).to_s <<
(delete_from_favorite_button(item, type_str) || favorite_button(@item, type_str)).to_s <<
share_button(@item).to_s <<
(content_tag(:div) { link_to("Edit", edit_path)} if current_user.is_mine?(@item)).to_s
end
end
end
Run Code Online (Sandbox Code Playgroud)
所以,这里几乎没有HTML代码.
你能不能给我一些建议,你认为哪种方法更好,为什么?此外,这些方法中是否存在一些性能问题(例如,多个字符串串联或频繁的部分加载可能代价高昂)?(这个应用程序相当高负载)
我正在通过将<img>
标记嵌入到网站来制作高负荷的网络统计系统.我想做的是:
我正在使用Ruby,我将制作一个纯机架应用程序来获取标题并将它们放入队列以进行进一步计算.
我无法解决的问题是,如何配置sphinx为Rack应用程序提供标头,并返回静态图像作为回复而无需等待Rack应用程序的响应?
此外,如果有更常见的Ruby解决方案,则不需要Rack.