Rails 3.1 Need to do in place editing on an Index page

依然范特西╮ 提交于 2019-12-01 13:53:56

What I wound up doing was:

Create a row in the table that was a TextArea and assigned the text area a class:

<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]

Create a controller for the updating of the field in the DB:

  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]

Create a jquery function keying off of the class I assigned to the Text Area that passed in the necessary params to the route from the controller...

  $('.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
        });

And that took care of it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!