Rails 3.1 需要在索引页面上进行就地编辑 [英] Rails 3.1 Need to do in place editing on an Index page
问题描述
我有一个带有自由格式评论字段的索引页.Comment 字段是另一个不相关的模型的一部分——长篇大论、一部分我、一部分用户.
I have an index page with a free form comment field. The Comment field is part of another model that is not associated-- long story, part me, part user.
我需要弄清楚的是用什么来做到这一点.我遇到了 Best In Place 的问题 (此处) 并且不确定这是否是可解析的路径.
What I need to figure out is what to use to do that. I ran into a problem with Best In Place (here) and am not sure if that is a resolvable path.
那么,有没有人有教程或建议来指导我对索引进行就地编辑?
So, does anyone have a tutorial or advice to point me to regarding doing in place editing for an index?
推荐答案
我最终做的是:
在表格中创建一行是 TextArea 并为文本区域分配一个类:
<td class="textcell" id="<%= crb_agenda.key %>"><%= text_area_tag 'comment', if @pdms_comment.user_comments.nil? == false then @pdms_comment.user_comments end, :rows => 3, :id => "_" + @pdms_comment.jira_key %><%= link_to "[+]", "#", :class => "comment_row" %></td>
[对不起,我对这个格式有一段时间的困扰]
[sorry I am having a devil of a time with the formatting for this]
创建一个控制器来更新数据库中的字段:
def comment_push
@jira_key = params[:key]
@comment = params[:comment]
@user_name = params[:name]
@user_pw = params[:pw]
@comment_record = Comment.find_by_jira_key(@jira_key)
@comment_record.update_attribute(:user_comments, @comment)
Comment.add_comment_to_jira_ticket(@user_name, @user_pw, "MCTEST-293",@comment)
respond_to do |format|
format.js
end
end
[note, this required a comment.js.erb file in the views; it was blank. Also, I created a route for it]
根据我分配给文本区域的类创建一个 jquery 函数,该类将必要的参数从控制器传递到路由...
$('.comment_row').live("click", function() {
var user_name = $('#user_name').val();
var user_pw = $('#user_pw').val();
var tr = $(this).closest("tr");
var td = $(this).closest("td");
var ta_id = '_' + td.attr("id");
var comment = $('textarea#' + ta_id).val();
$.ajax({
url: '/crbagenda/comments/comment_push',
type: 'GET',
data: 'key=' + td.attr("id") + "&name=" + user_name + "&pw=" + user_pw + "&comment=" + comment
});
这就解决了.
这篇关于Rails 3.1 需要在索引页面上进行就地编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!