0
我們使用fields_for和jquery在rails 3.2應用程序的表單上添加局部視圖。下面是代碼:jQuery在rails 3.2應用程序集成測試中無法使用嗎?
def link_to_add_fields(name, f, association)
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
render :partial => association.to_s, :locals => {:f => builder, :i_id => 0}
end
link_to_function(name, "add_fields(this, \"#{association}\", \"#{j fields}\")")
end
在applicaton.js:
function add_fields(link, association, content) {
var new_id = new Date().getTime();
var regexp = new RegExp("new_" + association, "g")
$(link).parent().before(content.replace(regexp, new_id));
}
每當「添加字段」被點擊的鏈接,該局部視圖被呈現和幾個輸入字段被添加到當前形式。代碼在執行時沒有任何問題。但是在集成測試(capybara
& launchy
)中,click_link('Add Field')
沒有做任何事情,導致部分失敗。是否在集成測試中啓用jquery?