rails 3 best_in_place edit not working without ref

2019-05-07 13:39发布

I took the comments code from Bernat's blog rails mini tutorial

I tried adding the edit in place functionality by using his best_in_place gem. For the most part it worked right

My code is deployed at http://falling-spring-3964.herokuapp.com/comments

You can look at the code here https://github.com/sunnygill/commentsapp

Problem:

  • I add a new comment. It shows up perfectly at the top of the page but the in place editing of the name does not work
  • if i refresh the page then in pace editing works

Question:

How can i make the in place editing work without refreshing the page

3条回答
倾城 Initia
2楼-- · 2019-05-07 14:02

I encountered the same problem, and my solution is add $('.best_in_place').best_in_place(); to the create.js.erb file.

查看更多
做个烂人
3楼-- · 2019-05-07 14:15

This is because you are not wiring the in-line-edit javascript plugin to the newly created HTML element (that holds the name to be editable) after completing the ajax call. I tried to look at your source code on Github, but it looks outdated.

查看更多
Luminary・发光体
4楼-- · 2019-05-07 14:24

Your controller isn't responding to JSON for the update method. Pretty simple to fix: simply add something like the following to your update action.

def update
  ...
  respond_to do |format|
    format.html { redirect_to @user}
    format.json { render json: @user }
  end
  ...
end
查看更多
登录 后发表回答