5

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

你能看看吗?提前致谢!

我的观点:

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

我的控制器:

 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

我认为问题来自我的控制器:

  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

你有线索吗?

4

3 回答 3

2

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

@project.overview = params[:value]
于 2010-07-28T09:29:02.830 回答
0

我学rails的时间不长,但我认为产品需要'@'。

像这样:

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

也许...

于 2010-07-28T08:38:27.213 回答
0

FYI -- The ID attributes must start with a letter. What you have in your view won't pass validation. You'll need to prepend it with some text in your templates and then strip it out in your application.js before sending it along in the submit data.

于 2010-12-16T02:58:05.843 回答