Skip to content

use `alias_method_chain` rather than overriding `render` directly #1

Merged
merged 2 commits into from Dec 3, 2013

2 participants

@ghiculescu

I noticed this wasn't playing nicely with wicked_pdf, which uses alias_method_chain to give different behaviour to the render method. FlashRender wasn't getting called as as result. Adding alias_method_chain to this gem fixes the issue (swapping the order of the gems in my Gemfile also worked, but this seems like a better way).

@ghiculescu

Sorry to bug @adamhunter , just wondering if you had a chance to look at this?

@adamhunter
Owner

hey, sorry was traveling for holiday. looking now.

@adamhunter adamhunter commented on an outdated diff Dec 2, 2013
lib/flash_render.rb
@@ -1,6 +1,16 @@
module FlashRender
-
- def render(*args)
+
+ def self.included(base)
+ # Protect from trying to augment modules that appear
+ # as the result of adding other gems.
+ return if base != ActionController::Base
@adamhunter
Owner
adamhunter added a note Dec 2, 2013

this could be clearer as return unless base == ActionController::Base

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@adamhunter adamhunter commented on an outdated diff Dec 2, 2013
lib/flash_render.rb
@@ -1,6 +1,16 @@
module FlashRender
-
- def render(*args)
+
+ def self.included(base)
+ # Protect from trying to augment modules that appear
+ # as the result of adding other gems.
+ return if base != ActionController::Base
+
+ base.class_eval do
@adamhunter
Owner
adamhunter added a note Dec 2, 2013

do you have to call class_eval here? wouldn't base.alias_method_chain :render, :flash work, or base.send?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@adamhunter
Owner

made a few comments, looks good overall. i'll merge and push a new version once we've figured out the specifics.

@ghiculescu

Thanks @adamhunter, I've updated based on those comments.

@adamhunter adamhunter merged commit c907a18 into adamhunter:master Dec 3, 2013
@adamhunter
Owner

release 1.2.0. thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.