sharing classes in rails and with other ruby scripts

S

shawn bright

[Note: parts of this message were removed to make it a legal post.]

Hey there all,

I have several Ruby classes that I need to share between several
applications.
Our company collects information from industrial machines, processes it, and
alerts our customers of system changes. This is either by text message,
website, etc..
So i have a ruby on rails website built that allows them to see whats up.
Then, we have other companies we build info sites on, kinda based on the
same code, but private labled, and modified in other ways too.

Here is what I would like, we have several websites that all have a
EquipmentSensor model, a ruby class of type ActiveRecord::Base, we also have
a folder of models that we 'require' to use in our data processing software,
and in our cron jobs, etc...

Is there a way i can share this class ( model ) with several different
websites running rails and also use it in my cron jobs, etc..

thanks for any tips.

sk
 
J

Joshua Ballanco

Shawn said:
Is there a way i can share this class ( model ) with several different
websites running rails and also use it in my cron jobs, etc..

Well, ActiveRecord is available as it's own gem, and a class which
inherits from ActiveRecord does not need the full Rails framework to be
useful (a bit of Googling should give you examples of ActiveRecord used
outside of Rails...or you could just look at Camping:
http://code.whytheluckystiff.net/camping). If you wanted, you could keep
your model collection in one place (say, /usr/lib/mycompanysstuff), and
then you would just need to modify your environment to require the model
classes from there...

...however! If you are constantly accessing the models from Rails apps,
it would probably be worth your while to look into setting up a
dedicated Rails app to serve up the model data and then access the data
from your other apps using ActiveResource. That solution has the
advantage of being scalable as well (...and ActiveResource is just dang
cool!).
 
S

shawn bright

[Note: parts of this message were removed to make it a legal post.]

Thanks for this, I am using these models in apps that are not rails apps
andy yes, It is pretty easy to do. I had some advice in the rails irc where
someone recommended the ActiveResource way to go. However, after having read
some on it, i don't think i can employ it here because it is pretty new and
my rails version is 1.2.4 If i upgrade to rails 2, i run the risk of
breaking my site (which is pretty large now) .

Thanks for your attention on this Joshua, and if you know of a good trick
that might work for me I would welcome any suggestions. Actually, it is
only about 4 of the models that i want to share, but if i do 4, i may as
well do them all.

thanks again
sk
 
J

Joshua Ballanco

Shawn said:
Thanks for your attention on this Joshua, and if you know of a good
trick that might work for me I would welcome any suggestions.

Well, I think it's important to remember that Rails is still Ruby, so
all the good ol' Ruby tricks still work. In other words, you can always
pull out common code into a lib and 'require' it. This would even work
for ActiveRecord subclasses.
 
S

shawn bright

[Note: parts of this message were removed to make it a legal post.]

cool, thanks for this.
sk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top