Sha256: 2809ab482123a75698db4a224791d8c0826ae41b41ba29b36202cc01b6b4835f

Contents?: true

Size: 818 Bytes

Versions: 3

Compression:

Stored size: 818 Bytes

Contents

# Models

Models are not separated by `frontend`, `backend` or `auth` and therefore do not need to be namespaced.

Create your model at `app/models/archangel/foo.rb` add the following.

```
module Archangel
  class Foo < ApplicationRecord
    before_validation :parameterize_slug

    validates :bar, presence: true
    validates :slug, presence: true, uniqueness: true

    belongs_to :site

    protected

    def parameterize_slug
      self.slug = slug.to_s.downcase.parameterize
    end
  end
end
```

To change the `id` for constructing a URL to this object you can override `#to_param` in your model to make `foo_path` construct a path using the record `slug` instead of the `id`. See [`#to_param`](https://apidock.com/rails/ActiveRecord/Base/to_param) for further explanation.

```
def to_param
  slug
end
```

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
archangel-0.0.5 docs/Extension/Models.md
archangel-0.0.4 docs/Extension/Models.md
archangel-0.0.3 docs/Extension/Models.md