Questions tagged [alias-method-chain]

18 questions
7
votes
1 answer

what is the difference between alias_method and alias_method_chain?

I was working on my web-application and I wanted to override a method for example if the original class is class A def foo 'original' end end I want to override foo method it can be done like this class A alias_method :old_foo, :foo …
4
votes
1 answer

Custom Helper with alias_method_chain on Ruby on Rails in development mode [REDMINE]

I would like to custom the method link_to_issue of the application_helper of Redmine with the principle of the alias_method_chain in order to keep the Redmine code clean in a plugin but I encounter a problem. First of all, here is the patch file,…
3
votes
3 answers

How to upgrade redmine plugin to rails 5, alias_method_chain is deprecated now

Story mode Just started learning RoR, but in short period of time I need to add functionality similar to Loading images from LDAP (incompatible version) into our project. Project is abondoned, and I can't find any related info/docs, so I'm asking…
3
votes
0 answers

Prepending to module that gets included/extended

I'm moving from using Module#alias_method_chain to Module#prepend. But there is one situation where I cannot achieve the same functionality Suppose I have a library code (two libraries actually, one of which enhances another) # Library 1 object =…
Roman Usherenko
  • 4,659
  • 4
  • 17
  • 14
3
votes
1 answer

alias_method, alias_method_chain, and self.included

I'm having a little difficulty understanding alias_method/alias_method_chain. I have the following code: module ActionView::Helpers module FormHelper alias_method :form_for_without_cherries, :form_for def form_for(record, options = {},…
PlankTon
  • 12,443
  • 16
  • 84
  • 153
2
votes
3 answers

How to modify Rails 3 form builder

What is the best way to override form_for? For example, in every form_for(@post), I would like to automatically set the
id attribute to @post.object_id, and add the following field: hidden_field_tag :form_id, @post.object_id Can I do this…
deb
  • 12,326
  • 21
  • 67
  • 86
2
votes
1 answer

alias_attribute and creating and method with the original attribute name causes a loop

Im trying to dynamically create a method chain in one attribute in my model. By now I have this function: def create_filtered_attribute(attribute_name) alias_attribute "#{attribute_name}_without_filter", attribute_name …
Tiago
  • 2,966
  • 4
  • 33
  • 41
2
votes
1 answer

Rails - alias_method_chain with a 'attribute=' method

I'd like to 'add on' some code on a model's method via a module, when it is included. I think I should use alias_method_chain, but I don't know how to use it, since my 'aliased method' is one of those methods ending on the '=' sign: class MyModel <…
kikito
  • 51,734
  • 32
  • 149
  • 189
1
vote
1 answer

class << self, alias_method, and monkey patching Mechanize::Cookie

I have an issue with Mechanize::Cookie misbehaving and I want to trying to monkey patch it. My code: class Mechanize::Cookie class << self; alias_method :old_parse, :parse end def self.parse(uri, str, log = Mechanize.log) puts 'new parse!' …
pguardiario
  • 53,827
  • 19
  • 119
  • 159
1
vote
1 answer

How can I omit the middle of a chain of methods?

Suppose I have a class with a save method, and three mixins which modify it using aliasing, e.g. module Callbacks def save_with_callbacks callback :before_save save_without_callbacks end end alias_method_chain :save,…
Simon
  • 25,468
  • 44
  • 152
  • 266
1
vote
2 answers

alias_method_chain on an HABTM attribute's setter isn't working

So I have a HABTM for both Posts and Topics. A Post HABTM Topics, and a Topic HABTM Posts. What I need to do is call some method in conjunction with calling post.topics=() This is what I've tried doing in Post.rb: def…
1
vote
1 answer

Undefined method with alias_method_chain

My model has attribute html. When I try to use alias_method_chain with setter html=, I get the error undefined method `name=' for class `Banner' But I use alias_method_chain with another attribute. class Banner < ActiveRecord::Base def…
Sergey Vernidub
  • 422
  • 5
  • 14
1
vote
1 answer

Overring a Rails core mixin method, and still being able to call the old method

Ok title is confusing, Ill tell you my problem first: the polymorphic_url method was changed in Rails 2.2.1 to include some extra functionality I need. However, I want to make the application still work in older versions of Rails, so I wanted to…
dalyons
  • 1,304
  • 3
  • 15
  • 23
0
votes
2 answers

How to fix activeuuid gem error while upgrading from Rails4 to Rails5

I am updating my application from rails 4 to rails 5. My application is using activeuuid gem. The activeuuid gem is using alias_method_chain internally and this method is deprecated in rails 5. Now when I am trying to start rails console, I am…
0
votes
1 answer

Can I use module#prepend instead of alias_method_chain to monkey patch this concern?

I am patching a concern in the Devise Token Auth gem. I have it working with alias_method_chain but am wondering if I can use module#prepend instead in this scenario? Note: We are on ruby 2.2.x Existing: DeviseTokenAuth::Concerns::User.module_eval…
blu
  • 12,905
  • 20
  • 70
  • 106
1
2