Ruby on rails 编辑和页面刷新后,Rails x-editable值相同

Ruby on rails 编辑和页面刷新后,Rails x-editable值相同,ruby-on-rails,ruby,twitter-bootstrap,x-editable,Ruby On Rails,Ruby,Twitter Bootstrap,X Editable,当编辑一个字符串时,它的值会在视觉上发生变化,但当我刷新页面时,该值会变为以前的值。 我使用bootstrap-x-editable-rails 1.5.1.1 gem进行编辑 控制器代码: module Admin class DoctypesController < AdminController before_action :set_doctype, only: [:show, :edit, :destroy, :update] def ind

当编辑一个字符串时,它的值会在视觉上发生变化,但当我刷新页面时,该值会变为以前的值。 我使用bootstrap-x-editable-rails 1.5.1.1 gem进行编辑

控制器代码:

module Admin
    class DoctypesController < AdminController
        before_action :set_doctype, only: [:show, :edit, :destroy, :update]
        def index
            @doctypes=DocumentType.order("title").page(params[:page])
        end

        def show
        end

        def new
        @doctype = DocumentType.new
        end

        def create
            @doctype=DocumentType.create(doctype_params)
            redirect_to admin_doctypes_path
        end

        def destroy
      @doctype.destroy
      redirect_to admin_doctypes_path
    end

    def update
        @doctype.update(doctype_params)
      redirect_to admin_doctypes_path
    end

    def edit

    end

    def set_doctype
        @doctype = DocumentType.find(params[:id])
      end

        private
      def doctype_params
      params.require(:document_type).permit(:id,:title)
        end
    end
end
部分路线:

               admin_doctypes GET    /admin/doctypes(.:format)                          admin/doctypes#index
                              POST   /admin/doctypes(.:format)                          admin/doctypes#create
            new_admin_doctype GET    /admin/doctypes/new(.:format)                      admin/doctypes#new
           edit_admin_doctype GET    /admin/doctypes/:id/edit(.:format)                 admin/doctypes#edit
                admin_doctype GET    /admin/doctypes/:id(.:format)                      admin/doctypes#show
                              PATCH  /admin/doctypes/:id(.:format)                      admin/doctypes#update
                              PUT    /admin/doctypes/:id(.:format)                      admin/doctypes#update
                              DELETE /admin/doctypes/:id(.:format)                      admin/doctypes#destroy
这就是它的工作原理

控制器:

def update
        if @doctype.update(title: params[:value])
        status = msg = 'ok' 
      else
        status = 'error'
        msg = @doctype.errors.full_messages.join(',')
      end

      if request.xhr?
        render :json => {
        :status => status,
        :msg => msg
      }
    end
  end
Html:


确保您已登录。如果编辑操作要求loginI以管理员身份登录,则这不是原因。
               admin_doctypes GET    /admin/doctypes(.:format)                          admin/doctypes#index
                              POST   /admin/doctypes(.:format)                          admin/doctypes#create
            new_admin_doctype GET    /admin/doctypes/new(.:format)                      admin/doctypes#new
           edit_admin_doctype GET    /admin/doctypes/:id/edit(.:format)                 admin/doctypes#edit
                admin_doctype GET    /admin/doctypes/:id(.:format)                      admin/doctypes#show
                              PATCH  /admin/doctypes/:id(.:format)                      admin/doctypes#update
                              PUT    /admin/doctypes/:id(.:format)                      admin/doctypes#update
                              DELETE /admin/doctypes/:id(.:format)                      admin/doctypes#destroy
def update
        if @doctype.update(title: params[:value])
        status = msg = 'ok' 
      else
        status = 'error'
        msg = @doctype.errors.full_messages.join(',')
      end

      if request.xhr?
        render :json => {
        :status => status,
        :msg => msg
      }
    end
  end
<% @doctypes.each do |doctype| %>
          <tr>
            <td>
              <div class="doctype_edit" data-type="text" data-url="/admin/doctypes/<%=doctype.id%>" data-name="title" data-pk=<%= doctype.id %> >
                <%= doctype.title%>
              </div>
            </td>

            <td>
                    <%= link_to '', :id => 'btn_remove_doctype', :data => { :path => admin_doctype_path(doctype), :toggle => 'modal', :target => '#modal_confirm_remove_doctype' }, :class => "btn btn-danger btn-xs" do %>
                  <span class='glyphicon glyphicon-remove'></span>
                <% end %>
            </td>
          </tr>
        <% end %>
$.fn.editable.defaults.mode = 'inline';
$.fn.editable.defaults.ajaxOptions = {type: "PATCH"};
  $('.doctype_edit').editable({
    inputclass: 'inputdoctype',
    success: function(response, newValue) {
        if(response.status == 'error') {
            return response.msg;
        } else {
          $('this').html(newValue);
        }
    }
  });