1
我在我的ApplicationHelper
方法之一使用link_to_function
:如何在助手中使用unobustrive JS重構link_to_function?
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(association.to_s + "_fields", :f => builder)
end
link_to_function(name, ("add_fields(this, '#{association}', '#{escape_javascript(fields)}')").html_safe)
end
,因爲它會在導軌4被淘汰,我想用Unobustrive JS擺脫link_to_function
。怎麼做?
也許這可以幫助:http://stackoverflow.com/questions/8617384/whats-the-best-ujs-way-of -refactoring-link-to-function – fmendez 2013-03-15 10:38:21
到目前爲止運氣還不錯? – Btuman 2013-06-05 15:12:39