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

前端 未结 1 1903
误落风尘
误落风尘 2021-01-17 04:33

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.

What I need

相关标签:
1条回答
  • 2021-01-17 05:14

    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.

    0 讨论(0)
提交回复
热议问题