https://github.com/atd/rails_engine_decorators
Extend Rails Engine’s business logic (models, controllers, helpers, etc.) easily from your application or other engine.
https://github.com/atd/rails_engine_decorators
Last synced: 10 months ago
JSON representation
Extend Rails Engine’s business logic (models, controllers, helpers, etc.) easily from your application or other engine.
- Host: GitHub
- URL: https://github.com/atd/rails_engine_decorators
- Owner: atd
- License: mit
- Created: 2012-09-28T17:17:21.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2017-01-24T18:59:07.000Z (over 9 years ago)
- Last Synced: 2025-08-20T19:46:07.942Z (10 months ago)
- Language: Ruby
- Homepage:
- Size: 29.3 KB
- Stars: 23
- Watchers: 2
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
Awesome Lists containing this project
README
= Rails Engine Decorators
Extend Rails Engine's business logic (models, controllers, helpers, etc.) easily from
your application or other engine.
This solution was first implemented in the Forem engine, see https://github.com/radar/forem/pull/260
== Authors
* Kunal Chaudhari, https://github.com/kunalchaudhari
* Ryan Bigg, https://github.com/radar
* Philip Arndt, https://github.com/parndt
* Antonio Tapiador, https://github.com/atd
== Usage
(From Forem's patch):
Standard practice for including such changes in your application or extension is to create a file within the relevant app/models or app/controllers directory with the original class name with _decorator appended.
### Adding a custom method to the Post model:
# app/decorators/models/forem/post_decorator.rb
Forem::Post.class_eval do
def some_method
...
end
end
### Adding a custom method to the PostsController:
# app/decorators/controllers/forem/posts_controller_decorator.rb
Forem::PostsController.class_eval do
def some_action
...
end
end
The exact same format can be used to redefine an existing method.