Decorators not reloading in development environment
Closed this issue · 11 comments
When I edit a decorator (for example the refinery page class [Refinery::Page.class_eval
]) Refinery::Page
gets reloaded and loses all decorator methods/attributes.
Also, when editing routes.rb
all decorator methods/attributes are lost.
This happens a lot during development, which is quite frustrating.
To get my site functional again I have to restart the rails server.
Can you provide a simple application that reproduces this issue please?
You can find the sample application here: https://github.com/jurriaan/refinery-bug-2267
Relevant files:
- https://github.com/jurriaan/refinery-bug-2267/blob/master/app/views/refinery/pages/show.html.erb
- https://github.com/jurriaan/refinery-bug-2267/blob/master/app/decorators/models/refinery/page_model_decorator.rb
- https://github.com/jurriaan/refinery-bug-2267/blob/master/config/routes.rb
How to reproduce:
- Start application (first create db and seed)
- Go to the home page. You’ll see ‘Page model is decorate’
- Edit the decorator (for example just add an empty line at the bottom of the decorator/routes file).
- Save it and refresh the homepage.
- It’ll now show: ‘Page model is NOT decorated’
Hi, I believe I'm seeing this issue with a 2.1.1 site. My rspec tests work fine, and the decorators work in Production -- just not in Dev.
The decorators are within a Refinery extension I've created (/vendor/extensions/concerts).
The decorator class is at .../app/decorators/models/refinery/concert_decorator.rb, within the engine/extension. I don't think there's a problem with the decorator itself, but it looks like:
Refinery::Concerts::Concert.class_eval do
def pretty_concert_date
concert_date.to_s(:long_date_with_time_12h)
end
etc.
end
Am I expected to have to make changes as per the notes you (@parndt) added in 0832884 and aabfe8c?
Is it possible I've got something wrong in the Gemfile for the Extension? I can provide more code if necessary.
Can you please show your engine.rb file?
module Refinery
module Concerts
class Engine < Rails::Engine
extend Refinery::Engine
isolate_namespace Refinery::Concerts
engine_name :refinery_concerts
initializer "register refinerycms_concerts plugin" do
Refinery::Plugin.register do |plugin|
plugin.name = "concerts"
plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.concerts_admin_concerts_path }
plugin.pathname = root
plugin.activity = {
:class_name => :'refinery/concerts/concert'
}
end
end
config.to_prepare do
::ApplicationController.helper(ConcertsHelper)
end
config.after_initialize do
Refinery.register_extension(Refinery::Concerts)
end
end
end
end
Change this line:
initializer "register refinerycms_concerts plugin" do
To this:
before_inclusion do
Per this commit 086e782
Very good! :-) Thanks! Certainly not something I would have worked out on my own...
Are there any known side-effects?
Is there a plan for this to be pushed to the 2.1 branch, or will this change eventually be part of the next release?
I'd love it if this change were ported to the 2-1-stable branch, is this something you'd like to do?
Yeah, I'm happy to do that. A little assistance may be required though...:
Question: from a clean checkout of the refinerycms repo, is it possible to build all the dependent parts in one go? Is there a shortcut, or do I need to go to each subdirectory and build all the gems one by one?
I forked the repo, and cherry-picked that commit. The change was not working until I build the refinerycms-core. First off I tried to build just the refinerycms.gemspec in the root folder, assuming it would bring in its dependencies -- that apparently isn't sufficient, since it (i'm guessing) grabs dependencies from gem rather than locally. After some confusion, I built both the ./core/refinerycms-core.gemspec and the main refinerycms.gemspec, and installed them explicitly using rvm -- in the path where my test install would be.
For what it's worth, the engine.rb in my generated extension looks good now, but I'm having a bit of trouble testing it with a real decorator function -- just my local setup I think. I'll send a pull-request in a couple of days when I'm confident everything is OK. (Although I'm pretty sure it is already.)
You don't need to build any gems whatsoever.. this guide may help you:
http://refinerycms.com/guides/contributing-to-refinery
With a fresh clone of the repository, you should just be able to type bundle install and then generate a dummy application with rake refinery:testing:dummy_app
Then you should be good to go.
Hi, Thanks for the link. It's much easier creating a dummy app 👍
I've just sent a pull request (#2513). I wasn't able to reproduce the bug with decorators after applying the commit, and it merges into the 2.1 stable branch without conflict. Happy to do the 2-1-globalize branch too if it's likely to be valuable to many people. Just let me know.