Hello. I have some code that I want to share between my models (i.e.: text formatting routines). Where would be the correct place to put it? Thanks in advance. Pepe --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ideally, you should write a plugin, more on that here -> https://peepcode.com/products/rails-2-plugin-patterns But you could also just create a simple module and make your models include it. On Wed, Sep 10, 2008 at 11:32 PM, pepe <Pepe-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote:> > Hello. > > I have some code that I want to share between my models (i.e.: text > formatting routines). Where would be the correct place to put it? > > Thanks in advance. > > Pepe > > >-- Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) João Pessoa, PB, +55 83 8867-7208 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Mauricio, If I write the module, do I just put it in the folder where all the modules are? On Sep 10, 10:33 pm, "Maurício Linhares" <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ideally, you should write a plugin, more on that here ->https://peepcode.com/products/rails-2-plugin-patterns > > But you could also just create a simple module and make your models include it. > > On Wed, Sep 10, 2008 at 11:32 PM, pepe <P...-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote: > > > Hello. > > > I have some code that I want to share between my models (i.e.: text > > formatting routines). Where would be the correct place to put it? > > > Thanks in advance. > > > Pepe > > -- > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > João Pessoa, PB, +55 83 8867-7208--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
No, you could put it at the "lib" folder and add a require for it in your user model. Putting your module at the helpers folder would make it be included in your view helpers, and i think this is not what you''re looking for :) On Wed, Sep 10, 2008 at 11:40 PM, pepe <Pepe-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote:> > Thanks Mauricio, > > If I write the module, do I just put it in the folder where all the > modules are? >-- Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) João Pessoa, PB, +55 83 8867-7208 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry, I should have said where all the ''models'' are. Sorry if I am little dense here but it''s the first time I do this and I want to make sure I understand. I create a module (''my_module.rb'') with my code and just drop the file in folder ''lib'', not in ''lib/tasks''. Then I issue a require ''my_module'' in my models and I''m ready to rock & roll? Thanks again. On Sep 10, 10:51 pm, "Maurício Linhares" <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No, you could put it at the "lib" folder and add a require for it in > your user model. > > Putting your module at the helpers folder would make it be included in > your view helpers, and i think this is not what you''re looking for :) > > On Wed, Sep 10, 2008 at 11:40 PM, pepe <P...-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote: > > > Thanks Mauricio, > > > If I write the module, do I just put it in the folder where all the > > modules are? > > -- > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > João Pessoa, PB, +55 83 8867-7208--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Thu, Sep 11, 2008 at 1:43 PM, pepe <Pepe-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote:> I create a module (''my_module.rb'') with my code and just drop the file > in folder ''lib'', not in ''lib/tasks''. Then I issue a require > ''my_module'' in my models and I''m ready to rock & roll?That''s right. -- http://lindsaar.net/ Rails, RSpec and Life blog.... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks so much to both. :) Pepe On Sep 10, 11:47 pm, "Mikel Lindsaar" <raasd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Sep 11, 2008 at 1:43 PM, pepe <P...-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote: > > I create a module (''my_module.rb'') with my code and just drop the file > > in folder ''lib'', not in ''lib/tasks''. Then I issue a require > > ''my_module'' in my models and I''m ready to rock & roll? > > That''s right. > > --http://lindsaar.net/ > Rails, RSpec and Life blog....--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Actually I think the module will be automatically included if you put it in the "lib" folder. You dont have to "require" it. mark --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You could define the model like this, as a file called lib/ shared_methods.rb module SharedMethods def to_s name end end and then just type include SharedMethods in any model you want to have that to_s method. ----- Ryan Bigg Freelancer Skype: radarlistener MSN & Gtalk: radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks to all. :) Pepe On Sep 11, 9:16 am, Ryan Bigg <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You could define the model like this, as a file called lib/ > shared_methods.rb > > module SharedMethods > def to_s > name > end > end > > and then just type include SharedMethods in any model you want to have > that to_s method. > > ----- > Ryan Bigg > Freelancer > Skype: radarlistener > MSN & Gtalk: radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---