https://github.com/hyperoslo/singleton-rails
Adds singleton functionallity to ActiveRecord models
https://github.com/hyperoslo/singleton-rails
Last synced: about 1 year ago
JSON representation
Adds singleton functionallity to ActiveRecord models
- Host: GitHub
- URL: https://github.com/hyperoslo/singleton-rails
- Owner: hyperoslo
- License: other
- Created: 2014-02-03T10:01:12.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2023-01-19T04:13:09.000Z (over 3 years ago)
- Last Synced: 2025-04-02T02:22:28.738Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 44.9 KB
- Stars: 8
- Watchers: 10
- Forks: 12
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Singleton Rails
[](https://rubygems.org/gems/singleton-rails)
[](https://gemnasium.com/hyperoslo/singleton-rails)
[](https://codeclimate.com/github/hyperoslo/singleton-rails)
Adds singleton functionallity to ActiveRecord models.
**Supported Rails versions: 4.0.6 or higher**
Licensed under the **MIT** license, see LICENSE for more information.
## Installation
$ gem install singleton-rails
## Usage
### Include Singleton in your model
```ruby
class AboutPage < ActiveRecord::Base
include ActiveRecord::Singleton
end
```
### Configure rails_admin
```ruby
RailsAdmin.config do |config|
config.actions do
dashboard
index &RailsAdmin::Config::Actions::SingletonAwareIndex::PATCH
new &RailsAdmin::Config::Actions::SingletonAwareNew::PATCH
export
history_index
bulk_delete
show
edit
delete &RailsAdmin::Config::Actions::SingletonAwareDelete::PATCH
history_show
show_in_app
end
end
```
### How to use it in your controller
```ruby
class AboutPageController < ApplicationController
def index
@about_page = AboutPage.instance
end
end
```
## Credits
Hyper made this. We're a digital communications agency with a passion for good code,
and if you're using this library we probably want to hire you.