parndt / decorators Goto Github PK
View Code? Open in Web Editor NEWManages the process of loading decorators into your Rails application.
License: MIT License
Manages the process of loading decorators into your Rails application.
License: MIT License
Hey there!
Figured since I also make files in app/decorators
that I should throw in two cents here. I don't want to trample over others' decorators, either.
Is this something I should be supporting in some way?
This probably because "Decorator" is a vague term, that can have a different meaning for each person.
The name to me seems like it would be for something that implements the decorator pattern; but, from your tweet, it appears this is for a different purpose. It seems like they are more like: Patchers, Patches, Mutators, or some other term that means it's modifying a class instead of wrapping instances of a class.
I use the decorators gem among other things for monkey patching DeviseController
. In the class_eval
block I use helper
to include my ApplicationHelper
and other helpers. This works fine in development, but in production I get a NoMethodError
in a view that tries to call a helper method in my ApplicationHelper
.
I double checked that my decorator get's loaded. I also added a before_filter
in the decorator and It's being called as well. Only the helpers aren't included.
Here's my code:
DeviseController.class_eval do
layout 'admin'
append_view_path 'app/views/admin'
has_mobile_fu
before_filter :init_js_framework_settings
$stderr.puts('GETS LOADED!')
protected
def init_js_framework_settings
@js_framework_settings = {
namespace: self.class.name.split('::')[0..-2],
controller: controller_name.camelize,
action: action_name
}
end
end
For a variety of reasons I won't go into here, I have to run my app with eager_load = true
in development (where cache_classes = false
). (I realize this is an unusual Rails setup for development env).
I'm trying to use this gem to handle decoration loading, but in this situation, the decorator is loaded twice on application initialization, once when the code is eager loaded (because Rails eager loads app/**/*
) and once when this gem runs its load!
method.
I tried various fixes changing when/where Decorators.load!
is run, but no luck. I was wondering if someone with a deeper understanding of the Rails autoloading and boot processes had any thoughts.
I am working on a legacy Rails 3.2 application that requires decorators through forem. Decorators 1.0.4, in our setup, throws the following error when attempting to start the application on Heroku or with bundle exec thin start -R config.ru -e production
:
/home/james/.rvm/rubies/ruby-2.1.4/lib/ruby/gems/2.1.0/gems/railties-3.2.17/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `eager_load' for #<Rails::Application::Configuration:0x0000000555cb48> (NoMethodError)
from /home/james/.rvm/rubies/ruby-2.1.4/lib/ruby/gems/2.1.0/gems/decorators-1.0.4/lib/decorators/railtie.rb:9:in `block in <class:Railtie>'
We're using Rails 3.2.17 and Railties 3.2.17. Not sure if this is intended behavior or not, but 1.0.3 works in our application, so this problem would go through pessimistic semver.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.