He All I have a situation in which I store all prices excl VAT. Now, this module needs to have the price incl VAT. How do I do this, for example, in the controllers I do something like my_model = Xyz.find(:first) .... my_model.price .... I don''t want to call (in all the controllers) a function like: my_model.convert_price The ''my_model'' should already have the price incl VAT. How do I do this in the model ? Thnx a lot LuCa -- 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 -~----------~----~----~----~------~----~------~--~---
define the vat amount as const somewhere in environment.rb like VAT = 1.19 (not necessary, but better is that...) then just define a method price_vat like def price_vat price * VAT end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Luca, You can try defining the method in application.rb and use before_filter macro to declare it in controllers. Would like to know more about filters? Refer this: http://www.therailsway.com/2006/11/16/tracks-part-2 Thanks, Kiran, http://kiran.gnufied.org On Jul 28, 3:36 pm, Thorsten Müller <thors...-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> wrote:> define the vat amount as const somewhere in environment.rb like > VAT = 1.19 > (not necessary, but better is that...) > > then just define a method price_vat like > > def price_vat > price * VAT > end--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I found an other very interesting way to do this (although it doesn''t work yet) just re-define the ''price'' method The question I have is: how do I create the same price method as activeRecord. (for testing only) For example: def price read_attribute(:price) end gives me problems (I get nil object etc), so ActiveRecord does more then this. Furthermore, is there a way to call the original price method, I tried something like def price super end which doesn''t work :( Any suggestions on this one ? -- 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 -~----------~----~----~----~------~----~------~--~---