【问题标题】:Rails Best_in_place edit issueRails Best_in_place 编辑问题
【发布时间】:2012-12-16 17:14:46
【问题描述】:

我正在尝试在我的 rails 应用程序中实现 best_in_place,但我不知道如何实现它。当我滚动需要编辑的文本时,它什么也没做。我在用户下有一个嵌套的配置文件模型,我想编辑用户名。但是名称在 Profile Model 下。所以我有“user.profile.name”。如前所述,我已按照安装步骤包含并安装了 gem,并将 jquery 文件包含在我的 application.js 中!

这是我的表演视图:

<%= best_in_place @profile, :name, :type => :input, :path => user_profile_path(@user) %>

这是我在用户控制器中的显示操作:

  def show
    @user = User.find_by_identifier!(params[:id])
    @profile = @user.profile
  end

这是我的个人资料控制器:

respond_to :html, :json

   def edit
     @user = User.find_by_identifier!(params[:user_id])
     @profile = @user.profile
   end

   def update
     @user = User.find_by_identifier!(params[:user_id])
     @profile = @user.profile
     @profile.update_attributes(params[:profile])
     respond_with @user
   end

这是我的 application.js 文件

//= require jquery
//= require jquery_ujs
//= require best_in_place
//= require best_in_place.purr
//= require_tree .

$(document).ready(function() {
  /* Activating Best In Place */
  jQuery(".best_in_place").best_in_place();
});

【问题讨论】:

  • 点击名称时出现文本框?如果是,编辑名称后控制台中的内容是什么?
  • 什么也没有出现。它就像我什至没有安装最好的?它什么也不做。只显示硬编码的名称!
  • 如果没有安装 best_in_place,在&lt;%= best_in_place ... %&gt; 上的视图渲染过程中会出现错误。这当然是一个javascript问题。您应该检查页面加载时是否存在 javascript 错误,是否存在 best_in_place javascript 文件,并且可能进行调试以找出问题所在:-/
  • 想通了。另一个使用旧版本 jquery 的 JS 文件与该文件发生冲突。当我不包括旧的时,它工作正常。谢谢!!
  • @pratski:请自己添加答案,然后接受。

标签: javascript ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 best-in-place


【解决方案1】:

感谢@baldrick。我有另一个使用旧版本 jQuery 的 jQuery 插件。我删除了与该插件相关的 JS,之后 Best_in_Place 工作正常。唯一的问题是我必须使用其中一个,因为它们会发生冲突,或者因为新版本不支持某些功能,所以需要找到其他插件与新版本 jQuery 一起工作的方法。

【讨论】:

    猜你喜欢
    • 2011-08-01
    • 2015-09-11
    • 1970-01-01
    • 2023-03-13
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多