Skip to main content
Last updated: 23 Jul 2021

smart-answers: How to retire a Smart Answer

The process to retire a published Smart Answer involves removing the code for the Smart Answer and then using an unpublish task to update GOV.UK the content item that represents the Smart Answer flow.

Remove Smart Answer code

Remove all the files and directories associated with the individual Smart Answer and their associated tests, examples of common files:

  • Flow class files
    • app/flows/<\smart-answer>_flow.rb
  • ERB templates directory
    • app/flows/<\smart-answer>_flow
  • YAML files
    • config/smart_answers/rates/<\smart-answer>.yml
    • config/smart_answers/<\smart-answer>.yml
  • Calculators, data query and other ruby files
    • lib/smart_answer/calculators/<\smart-answer>_calculator.rb
    • lib/smart_answer/calculators/<\smart-answer>_data_query.rb

Removing the content item

Before removing a Smart Answer you will need the content_id for the Smart Answer. These can be found in the app/flows/<\smart-answer>_flow.rb file of the Smart Answer that is being retired. For redirecting or replacing a Smart Answer you will also need to know the paths of these pages these are based off the name attribute of the app/flows/<\smart-answer>_flow.rb file. For example, for the Marriage Abroad Smart Answer the path is /marriage-abroad.

Redirecting users to a different URL

To send visitors to the Smart Answer to a new page you can run the unpublish_redirect task. For example to redirect requests to a new destination, /random, you'd run the following rake task:

bundle exec rake "publishing_api:unpublish_redirect[<content_id>,<base_path>,/random,prefix]"

Applying this to the Marriage Abroad Smart Answer you'd run the following command:

bundle exec rake "publishing_api:unpublish_redirect[d0a95767-f6ab-432a-aebc-096e37fb3039,/marriage-abroad,/random,prefix]"

Showing users a page to indicate the content is no longer available

If there is not content to replace the Smart Answer then the convention is to serve a page that indicates there used to be content but isn't anymore (a 410 gone HTTP response). An example of how to perform this is:

bundle exec rake publishing_api:unpublish_gone[<content_id>]

It is possible to remove the Smart Answer and rather than serve a 410 Gone page instead serve a 404 Not Found, which misleads visitors to the page that content had never been published there. This can be done by using the publishing_api:unpublish_vanish task instead of the gone equivalent. This task should only be used in exceptional circumstances for example an accidental early publishing of content with a sensitive URL.

Replace a Smart Answer with a different content type

Sometimes there will be a need to replace a Smart Answer with a different type of content, typically these have been transactions, answers and start pages that can be published through Publisher.

The next step is to perform a temporary removal of the Smart Answer page(s) to be replaced. You can use the aforementioned publishing_api:unpublish_gone task to perform this.

You can then run a rake task command to reserve the path(s) used by the Smart Answer for a different publishing application. For example, to reserve the Marriage Abroad start page for Publisher you can perform the following command:

bundle exec rake "publishing_api:change_owning_application[/marriage-abroad,publisher]"

Once this is complete you can then create a new piece of content with the URL the Smart Answer page previously used.

NOTE: Start pages once existed in Publisher, and artefacts may persist in Publisher's database with current Smart Answer slugs. This may prevent a Smart Answer being replaced by a new document type as Publisher is still reserving the slug. [You will need to delete the old artefact]https://github.com/alphagov/publisher/pull/1474/files), once confirmed it is no longer needed.