Ronald Fischer wrote in post #1150799: > My Rails application also contains classes which are independent from > the Rails framework, in that they could be reused unchanged if I would, > for example, created a non-web-based, command-line version of my app. > Such a class could be one which implements business logic, or a simple > utility class. > > The question is: What is a good practice of integrating it? > > In a "non-Rails" application, I would create a directory app/lib and put > the rb files there. I would ensure, that RUBYLIB points to this > directory, and I would do a "require" in those files where the classes > are needed. > > This should also work within Rails. However, is this good practice? How > are experienced Rails developers handle this? > > Note also, that these classes will be instantiated only inside a > controller, not in a view or model.
Ruby has a mechanism for this. They are called "gems", libraries of shared code. Rails provides a "lib" directory for code more tightly coupled with the application in which they are used. If you do have model classes that are not subclasses of ActiveRecord there's still no reason they can't live inside the models directory along side your ActiveRecord subclasses. Ruby also provides modules and mix-ins for adding functionality to existing classes, this can often be a good way to implement utility methods. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cef32e2678b9a24af0f4d6ccbb8886ca%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.

