在就地编辑使用Rails,jQuery和best_in_place宝石 [英] In-place editing with Rails, jquery and best_in_place gem
问题描述
我有一个任务列表应用程序中,任务显示的类别。
I've got a task list app where tasks are displayed by category.
我在两地上市的类别。我允许就地使用best_in_place宝石要编辑的类别名称。我有工作的罚款。我的问题是,因为我在两个地方的类别名称,我只能编辑就地一次出现的话,我需要的不是编辑,以使用新名称进行更新的形式提交后名称的其他外观。什么是刷新的最佳方式/重装受影响的类的名字?
I have the categories listed in two places. I'm allowing the category name to be edited in-place using the best_in_place gem. I have that working fine. My issue is that since I have the category name in two places and I'm only editing one occurrence of it in-place, I need the other appearance of the name that was not edited to be updated with the new name after the form submits. What would be the best way to refresh/reload the affected category's name?
感谢。
推荐答案
如果你有这样的code(HAML)
If you have this code (haml)
= best_in_place @user, :name, :classes => 'name-edit'
您确实需要一个回调。然而,在回调处理程序的情况下,这个重presents电话是从取得的元素,所以你可能只是做
You do need a callback. However, in the context of the callback handler, 'this' represents the element the call was made from, so you could just do
$('.name-edit').on 'ajax:success', (event, data, status, xhr) ->
$('.some-other-widget').html this.innerHTML
和获得新价值的其他部件的方式。在调用的事件处理程序后面也有currentTarget当前作为一个属性,它是一个开始Ajax请求的部件。但是,我不认为这需要的。
and get the new value to the other widget that way. The event in the call back handler also has currentTarget as a property, which is the widget that started the ajax request. However, I don't think that's needed.
这篇关于在就地编辑使用Rails,jQuery和best_in_place宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!