[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

sharing classes in rails and with other ruby scripts

shawn bright

8/17/2008 5:27:00 AM

[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

4 Answers

Joshua Ballanco

8/19/2008 1:14:00 AM

0

Shawn Bright wrote:
> 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.n...). 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!).
--
Posted via http://www.ruby-....

shawn bright

8/19/2008 3:50:00 AM

0

[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

On Mon, Aug 18, 2008 at 8:14 PM, Joshua Ballanco <jballanc@gmail.com> wrote:

> Shawn Bright wrote:
> > 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.n...). 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!).
> --
> Posted via http://www.ruby-....
>
>

Joshua Ballanco

8/19/2008 5:31:00 AM

0

Shawn Bright wrote:
> 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.
--
Posted via http://www.ruby-....

shawn bright

8/19/2008 1:38:00 PM

0

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

cool, thanks for this.
sk

On Tue, Aug 19, 2008 at 5:31 AM, Joshua Ballanco <jballanc@gmail.com> wrote:

> Shawn Bright wrote:
> > 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.
> --
> Posted via http://www.ruby-....
>
>