forked from amatsuda/jquery-rjs
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change allows both patches in this gem to utilize Ruby 2's `Module.prepend` instead of ActiveSupport's `alias_method_chain` when possible. Normally I would drop support of Ruby < 2 and just rely on prepend, but as this gem is largely for legacy purposes this now allows for both methods depending on the version of Ruby used. This removes current deprecation warnings with Rails 5 and will allow continued use of the gem once alias_method_chain is removed from ActiveSupport.
- Loading branch information
1 parent
17772e4
commit 0b45627
Showing
2 changed files
with
36 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
require 'action_view/helpers/rendering_helper' | ||
|
||
ActionView::Helpers::RenderingHelper.module_eval do | ||
def render_with_update(options = {}, locals = {}, &block) | ||
module JqueryRjs::RenderingHelper | ||
method_name = "render#{'_with_update' if RUBY_VERSION < '2'}" | ||
define_method(method_name) do |options = {}, locals = {}, &block| | ||
if options == :update | ||
update_page(&block) | ||
else | ||
render_without_update(options, locals, &block) | ||
args = options, locals, block | ||
RUBY_VERSION < '2' ? render_without_update(*args) : super(*args) | ||
end | ||
end | ||
|
||
alias_method_chain :render, :update | ||
end | ||
end | ||
|
||
|
||
if RUBY_VERSION < '2' | ||
ActionView::Helpers::RenderingHelper.module_eval do | ||
include JqueryRjs::RenderingHelper | ||
alias_method_chain :render, :update | ||
end | ||
else | ||
ActionView::Helpers::RenderingHelper.prepend(JqueryRjs::RenderingHelper) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters