【问题标题】:Why does best_in_place editor not work with jquery?为什么 best_in_place 编辑器不适用于 jquery?
【发布时间】:2013-11-08 02:15:29
【问题描述】:

我正在尝试让 best_in_place 与我的应用程序一起工作。在我看来,默认情况下 best_in_place 对我有用:

<%= best_in_place @user, :first_name %>

当我使用下面的脚本导入 jquery-ui 时,它停止工作,即它显示为简单的文本。

<script src="/js/jquery-1.9.1.js"></script>
<%= best_in_place @user, :first_name %>

html源也没有改变

<span class='best_in_place' id='best_in_place_user_1_first_name' data-url='/users/1' data-object='user' data-attribute='first_name' data-type='input'>Ed</span>

知道如何让 jquery-ui 和 best_in_place 共存吗?

我的控制器,以防万一:

def edit
  @user = User.find(params[:id])
end

def update
@user = User.find params[:id]

 respond_to do |format|
  params[:user].delete(:password) if params[:user][:password].blank?
  if @user.update_attributes(params[:user])
    flash[:notice] = "Profile updated"
    format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
    format.json { respond_with_bip(@user) }
    sign_in @user
  else

    format.html { render :action => "edit" }
    format.json { respond_with_bip(@user) }
    sign_in @user
  end
 end
end

【问题讨论】:

  • 澄清一下:问题与添加 jQuery 或 jQuery-ui 有关吗?您引用的脚本是 jQuery,但您引用的是 jQuery-ui。
  • 感谢指出——我的错,意思是 jquery,没有 ui

标签: jquery ruby-on-rails best-in-place


【解决方案1】:

这只是猜测,但可能是 jquery 被多次包含的情况 - 无论是通过 best_in_place gem、jquery gem 还是资产管道领域的其他地方。在 chrome 中检查您的 javascript 控制台是否有错误,并将其包含在此处。

【讨论】:

  • 我在添加 jquery 时在 applicatoin.js 文件中收到以下错误。 (没有它不会出现错误)'Uncaught TypeError: Object [object object] has no method best_in_place'
  • 是的,听起来您遇到了我描述的问题。我相信在您尝试手动包含 Jquery 之前,您可能已经将 jquery 包含在 gem 中。尝试在不包括 jquery 的情况下自己运行代码?也许它会起作用!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-07
  • 2012-09-27
  • 2018-03-11
  • 2012-07-19
  • 2013-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多