MrBanabas-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Sep-23 13:09 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Rudy
2007-Sep-23 13:59 UTC
Re: Overwrite ActiveRecord gem function in my rails app
MrBanabas-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org 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? > > -- > VolkerYeah, 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Sep-23 17:57 UTC
Re: Overwrite ActiveRecord gem function in my rails app
See also alias_method_chain if you want to overwrite but still call through to the original function Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Rudy
2007-Sep-23 19:45 UTC
Re: Overwrite ActiveRecord gem function in my rails app
Frederick Cheung wrote:> See also alias_method_chain if you want to overwrite but still call > through to the original function > > FredIndeed Freddy, Although I quite like doing my aliases as "blah_before_blah" and "blah_after_blah" rather than with / without. but... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MrBanabas-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Sep-24 07:38 UTC
Re: Overwrite ActiveRecord gem function in my rails app
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MrBanabas-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Sep-24 07:52 UTC
Re: Overwrite ActiveRecord gem function in my rails app
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}[http://en.wikipedia.org/wiki/ 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Rudy
2007-Sep-24 09:59 UTC
Re: Overwrite ActiveRecord gem function in my rails app
MrBanabas-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org 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}[http://en.wikipedia.org/wiki/ > 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. > > -- > Volkerhmm... well I tried overwriting the Quoting module, and it works.>> module ActiveRecord::ConnectionAdapters::Quoting >> def quote(value, column=nil) >> return "quoting module" >> end >> endso perhaps you were doing something else wrong. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---