[英]jeditable and rails 3
I'm trying to use jeditable with my rails 3 apps. 我正在尝试使用我的rails 3应用程序进行jeditable。 I would like to edit some fields inline.
我想内联编辑一些字段。 Actually it's working on my client side but the data isn't updated in my app.
实际上它在我的客户端工作,但数据没有在我的应用程序中更新。
Could you take a look? 你能看看吗? Thanks in advance!
提前致谢!
my view: 我的观点:
<dt>Overview :</dt>
<dd class="edit_textfield" id="<%= @project.id %>" name="overview"><%= @project.overview %></dd>
my controller: 我的控制器:
def update
project = Project.find(params[:id])
overview = params[:value]
project.save
render :text => params[:value]
end
my application.js: 我的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') }
});
});
Thanks to kschaper, it works. 感谢kschaper,它有效。
But when I use jeditable for 2 fields in my page and that I edit them, only one is saved. 但是当我在页面中使用2个字段的jeditable并且我编辑它们时,只保存了一个。 Rails believe that the second value is 0
Rails认为第二个值是0
I think that the problem come from my 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
Do you have a clue? 你有线索吗?
Is overview an attribute of project? 概述是项目的属性吗? Then it should be
那应该是
@project.overview = params[:value]
I study rails not long, but I think the product need '@'. 我学习轨道的时间不长,但我觉得产品需要'@'。
Like this: 像这样:
def update
@project = Project.find(params[:id])
overview = params[:value]
@project.save
render :text => params[:value]
end
Maybe... 也许...
FYI -- The ID attributes must start with a letter. 仅供参考 - ID属性必须以字母开头。 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.
您需要在模板中添加一些文本,然后在application.js中将其删除,然后再在提交数据中发送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.