Skip to main content
 首页 » 编程设计

jquery之jeditable 和 Rails 3

2026年07月28日8wayfarer

我正在尝试在我的 Rails 3 应用程序中使用 jeditable。我想内联编辑一些字段。 实际上它在我的客户端工作,但数据没有在我的应用程序中更新。

你能看一下吗?提前致谢!

我的看法:

<dt>Overview :</dt> 
<dd class="edit_textfield" id="<%= @project.id %>" name="overview"><%= @project.overview %></dd> 

我的 Controller :

 def update 
    project = Project.find(params[:id]) 
    overview = params[:value] 
    project.save 
    render :text => params[:value] 
  end 

我的application.js:

$(".edit_textfield").each( function() {     
      $(this).editable('update', { 
            type    :   'textarea', 
            cancel  :   'Cancel', 
            submit  :   'OK', 
            indicator   :   'Saving...', 
            tooltip :   'Click to edit...', 
            rows        :       10, 
            method      :       "put", 
            submitdata  :   {id: $(this).attr('id'), name:$(this).attr('name') } 
        }); 
}); 
<小时 />

感谢 kschaper,它可以工作了。

但是当我对页面中的 2 个字段使用 jeditable 并编辑它们时,只保存一个字段。 Rails 认为第二个值为 0

我认为问题出在我的 Controller 上:

  def update 
    @project = Project.find(params[:id]) 
    @project.name = params[:name]  
    @project.overview = params[:overview] 
    @project.save 
    respond_to do |format| 
      format.js  #{ render :text => params[:value] } 
 
    end 
  end 

你有线索吗?

请您参考如下方法:

概述是项目的属性吗?那么应该是

@project.overview = params[:value]