Skip to content

Commit

Permalink
Use syntax highlighting for the README
Browse files Browse the repository at this point in the history
  • Loading branch information
makmic authored Oct 18, 2024
1 parent 913a72e commit 8258f2c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ Default values for ActiveRecord models.

In your `Gemfile`

```
```rb
gem 'has_defaults'
```

Now run

```
```sh
bundle install
```

## Usage

Add the method call `has_defaults` to your model.

```
```rb
class Page < ActiveRecord::Base
has_defaults :title => "New page", :body => "Put your text here"
end
Expand All @@ -30,19 +30,19 @@ Attributes will be set only if it's a new record and the attribute is blank.

Retrieve the default attribute with the `default_for` instance method:

```
```rb
@page.default_for(:title)
```

You can pass Proc as attribute:

```
```rb
has_defaults :expires_at => proc { Time.now }
```

You can override the default attributes as follow:

```
```rb
Page.has_defaults_options = {:title => "Here's your new page", :body => "Write your page text"}
```

Expand Down

0 comments on commit 8258f2c

Please sign in to comment.