Route overrides

This is the official documentation of the agent_ruby Ruby agent.

Route overrides ↗ allowed customizing the behavior of the routes exposed by the agent.

This very low-level feature was used to implement many use cases:

  • Attach handlers to events in the UI

  • Customize filtering, search and sort behaviors

  • Other advanced use cases.

Because our new agent API is higher-level, the protocol used to communicate between the agent and the application can no longer be manipulated.

Code cheatsheet

What was the route override used for?
How to migrate it?

Add custom permissions

Add validation to fields

Add validation to whole records

Run code on UI events

Change the search behavior

Change the filtering behavior of fields

Change the sort behavior of fields

Other use case

Examples

Add custom permissions

Custom permissions would better be implemented by using the Roles ↗ feature from the UI.

  • Define a new route into your routes.rb file:

  • Add a new method in your controller.

module ForestLiana
  class BooksController < ForestLiana::ApplicationController
    def destroy
      Book.find(params[:id]).destroy

      head :no_content
    end
  end
end

Add validation to fields

  • Define a new route into your routes.rb file.

  • Add a new method to your controller.

module ForestLiana
  class CompaniesController < ForestLiana::ApplicationController
    def create
      if params[:name] && params[:name].match?(/^Forest/)
        head :bad_request, content_type: 'application/json'
      else
        super
      end
    end

    def update
      if params[:name] && params[:name].match?(/^Forest/)
        head :bad_request, content_type: 'application/json'
      else
        super
      end
    end
  end
end

Run code on UI events

module ForestLiana
  class CustomersController < ForestLiana::ApplicationController
    def create
      begin
        superagent.post('https://my-company/create-card').set(
          'X-API-Key', '**********'
        ).end()
      ensure
        super
      end
    end
  end
end

Last updated