How to Fix in Ruby on Rails the Undefined Method 'Alias_Method_Chain' Error

undefined method `alias_method_chain' updating Spree from 3.2 to 3.3

For anyone else bumping into this, the multi_fetch_fragments gem has been merged into rails 5 itself and so the line

gem 'multi_fetch_fragments'

in my Gemfile was the culprit. Sources:
https://github.com/n8/multi_fetch_fragments/issues/34 and https://github.com/rails/rails/pull/18948

The error was gone after removing this gem from my Gemfile.

Rails - alias_method_chain with a 'attribute=' method

alias_method_chain is a simple, two-line method:

def alias_method_chain( target, feature )
alias_method "#{target}_without_#{feature}", target
alias_method target, "#{target}_with_#{feature}"
end

I think the answer you want is to simply make the two alias_method calls yourself in this case:

alias_method :foo_without_bar=, :foo=
alias_method :foo=, :foo_with_bar=

And you would define your method like so:

def foo_with_bar=(value)
...
end

Ruby symbols process the trailing = and ? of method names without a problem.

Replace 'alias_method_chain :save_attachments, :pasted_images' in Rails 5.2.3

Instead of

alias_method_chain :index, :esi

you'll just use

alias_method :index_without_esi, :index
alias_method :index, :index_with_esi

It was some kind of syntactic sugar.



Related Topics



Leave a reply



Submit