You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: chatables_controller.rb
    path of file: ./repos/discourse/plugins/chat/app/controllers/chat/api
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

class Chat::Api::ChatablesController < Chat::ApiController
  before_action :ensure_logged_in

  def index
    with_service(::Chat::SearchChatable) do
      on_success { render_serialized(result, ::Chat::ChatablesS
    
  def index
    with_service(::Chat::SearchChatable) do
      on_success { render_serialized(result, ::Chat::ChatablesSerializer, root: false) }
      on_failure { render(json: failed_json, status: 422) }
      on_failed_contract do |contract|
        render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
      end
    end
  end