问题
I have a list of records on my page. I submit a form remotely via AJAX and the new record is appended to the list. All best_in_place features immediately work apart from the :nil option. This doesn't display the default value that I set. This makes it impossible to edit the value unless the user refreshes the page. Then the value is present and the user can click.
Is this a known bug? Can anyone suggest a work around?
Updated with my code:
<%= best_in_place_if can?(:update, post), post, :post_type, :path => account_post_path(account,post), :type => :select, :collection => Post::POST_TYPES.zip(Post::POST_TYPES), html_attrs: { "class" => "span2" }, :nil => "Click to assign" %>
This is inside a partial called _post.html.erb that gets inserted via a create.js.erb file:
$("#js_posts").prepend("<%= escape_javascript render 'post', :post => @post, :account => @account %>");
$("#js_add_post_button").button('toggle');
$("#js_add_post").collapse('hide');
$("#js_add_post").html("<%= escape_javascript render 'add_post', :new_post => Post.new, :account => @account %>");
来源:https://stackoverflow.com/questions/18725948/best-in-place-nil-function-does-not-work-in-ajax-inserted-partial