Skip to content

Commit

Permalink
external link (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob authored Dec 20, 2024
1 parent 580344d commit 7260555
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/3.0/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,35 @@ class Avo::Resources::User < Avo::BaseResource
end
```
</Option>

<Option name="`self.external_link`">

<VersionReq version="3.15.6" />

<br>
<br>

<Image src="/assets/img/resources/external-link.png" width="1293" height="426" alt="External link demonstration" />


It's often desirable to provide users with a link to the public path of a record outside of the Avo interface. The `external_link` option allows you to achieve this.

### Usage

To define an external link for a resource, set the `self.external_link` option with a lambda function. Within this lambda function, you gain access to all attributes of [`Avo::ExecutionContext`](execution-context) along with the `record`.

```ruby{2-4}
class Avo::Resources::Post < Avo::BaseResource
self.external_link = -> { # [!code focus]
main_app.post_path(record) # [!code focus]
} # [!code focus]
end
```

The `self.external_link` lambda should return a string representing the URL of the record.

You can use path helpers from your application (e.g., `main_app.post_path`) or any external URL generator.

When this option is configured, Avo will display an external link button for the resource. Clicking it will take the user to the specified URL.

</Option>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7260555

Please sign in to comment.