Overwrite ActiveRecord gem function in my rails app

Hi,

I would like to overwrite the function “quote” in
ActiveRecord::ConnectionAdapters::Quoting for my whole rails
application.

Unfortunelty, so far I was nt successfull. Maybe somebody can point me
in the right direction?


Volker

[email protected] wrote:

Hi,

I would like to overwrite the function “quote” in
ActiveRecord::ConnectionAdapters::Quoting for my whole rails
application.

Unfortunelty, so far I was nt successfull. Maybe somebody can point me
in the right direction?


Volker

Yeah,
I think you just want to overwrite it for the specific connection
adapter.
Do “ActiveRecord::Base.connection.class”,

reopen that class,
and redefine quote on that class.

See also alias_method_chain if you want to overwrite but still call
through to the original function

Fred

Frederick C. wrote:

See also alias_method_chain if you want to overwrite but still call
through to the original function

Fred
Indeed Freddy,

Although I quite like doing my aliases as “blah_before_blah” and
“blah_after_blah”
rather than with / without.
but…

Hi,

Ok, after some further try and errors…
I ve achieved what I want with the following code:
module ActiveRecord
module ConnectionAdapters # :nodoc:
class AbstractAdapter
# Quotes the column value to help prevent
# {SQL injection attacks}[Wikipedia, the free encyclopedia
SQL_injection].
def quote(value, column = nil)

As suggested, I ve tried this time to overwrite the AbstractAdapter
class and not the quoting module.

Thanks a lot.


Volker

[email protected] wrote:

Hi,

Ok, after some further try and errors…
I ve achieved what I want with the following code:
module ActiveRecord
module ConnectionAdapters # :nodoc:
class AbstractAdapter
# Quotes the column value to help prevent
# {SQL injection attacks}[Wikipedia, the free encyclopedia
SQL_injection].
def quote(value, column = nil)

As suggested, I ve tried this time to overwrite the AbstractAdapter
class and not the quoting module.

Thanks a lot.


Volker

hmm…
well I tried overwriting the Quoting module,
and it works.

module ActiveRecord::ConnectionAdapters::Quoting
def quote(value, column=nil)
return “quoting module”
end
end

so perhaps you were doing something else wrong.

Hi,

The theory I ve understood…
Unfortunelty, ive got no idea how to actually do it.

I ve tried the following:
I ve created a quoting.rb in my rails app lib folder.
module ActiveRecord
module ConnectionAdapters # :nodoc:
module Quoting
def quote(value, column = nil)
my new code…

Afterwards I ve added a require of my little quoting file into my
environment file… well, but that does not work
So, you mentioned that just reopen the class and …
How do I actually do that?


Volker