Skip to content

Commit

Permalink
Merge branch 'main' of github.com:avo-hq/avodocs
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Mar 13, 2024
2 parents 1570ec0 + 4b0df53 commit 23f80aa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/3.0/field-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ You can also format using Rails helpers like `number_to_currency` (note that `vi
field :price, as: :number, format_using: -> { view_context.number_to_currency(value) }
```

## Parse value before update
When it's necessary to parse information before storing it in the database, the `update_using` option proves to be useful. Inside the block you can access the raw `value` from the form, and the returned value will be saved in the database.

```ruby
field :metadata,
as: :code,
update_using: -> do
ActiveSupport::JSON.decode(value)
end
```

## Sortable fields

One of the most common operations with database records is sorting the records by one of your fields. For that, Avo makes it easy using the `sortable` option.
Expand Down

0 comments on commit 23f80aa

Please sign in to comment.