# Rails models + database updates from outside rails

**URL:** <https://www.ruby-forum.com/t/rails-models-database-updates-from-outside-rails/190672>\
**Category:** Rails\
**Created:** [June 24, 2010, 11:24pm UTC](https://www.ruby-forum.com/t/rails-models-database-updates-from-outside-rails/190672 "2010-06-24T23:24:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5e925/32.png) [@rmk](https://www.ruby-forum.com/u/rmk)\
**Post date:** [June 24, 2010, 11:24pm UTC](https://www.ruby-forum.com/t/rails-models-database-updates-from-outside-rails/190672/1 "2010-06-24T23:24:29Z")

</div>

Hi Folks,

I am newbie to RoR, and I was looking for a way to do the following:

1. Run a service that provides a RESTful API.
2. Use the rails ORM (it is really convenient)
3. Keep the models up to date with data from another source on the  
system (in addition to updates to the models via rails controllers).

Now, RoR is great for 1 and 2. For 3, I am thinking of writing a  
daemon, but the daemon needs access to the database (possibly via the  
Rails ORM).  
Another constraint is that I am using a JRuby-based system.

Has anybody attempted something like this before? What have you used?  
Please share your experiences.

Thanks,  
Radhesh

---

<div class="post-metadata">

**Author:** ![rmk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5e925/32.png) [@rmk](https://www.ruby-forum.com/u/rmk)\
**Post date:** [June 25, 2010, 1:08am UTC](https://www.ruby-forum.com/t/rails-models-database-updates-from-outside-rails/190672/2 "2010-06-25T01:08:43Z")

</div>

On Thu, Jun 24, 2010 at 2:00 PM, Radhesh K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am newbie to RoR, and I was looking for a way to do the following:

> 1. Keep the models up to date with data from another source on the  
> system (in addition to updates to the models via rails controllers).
> 
> Now, RoR is great for 1 and 2. For 3, I am thinking of writing a  
> daemon, but the daemon needs access to the database (possibly via the  
> Rails ORM).

You almost certainly want to use the same ORM to access the DB  
so the same business logic (validations, etc.) is used.

Your use case is pretty vague, but sure, daemon, cron job, whatever  
works. 🙂

> Another constraint is that I am using a JRuby-based system.

Shouldn’t matter.

> Has anybody attempted something like this before?

No different than using script/runner for one-offs or cron jobs, or the  
Rails console, etc.

## FWIW,

Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![rmk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5e925/32.png) [@rmk](https://www.ruby-forum.com/u/rmk)\
**Post date:** [June 25, 2010, 7:01am UTC](https://www.ruby-forum.com/t/rails-models-database-updates-from-outside-rails/190672/3 "2010-06-25T07:01:07Z")

</div>

On Thu, Jun 24, 2010 at 4:07 PM, Hassan S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You almost certainly want to use the same ORM to access the DB  
> so the same business logic (validations, etc.) is used.
> 
> Your use case is pretty vague, but sure, daemon, cron job, whatever  
> works. 🙂

So a daemon goes into the lib directory and can be started whenever  
Rails starts?

> > Another constraint is that I am using a JRuby-based system.

I heard that the ‘daemon’ ruby gem works only for MRI and not on  
JRuby, is that true?

---

<div class="post-metadata">

**Author:** ![rmk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5e925/32.png) [@rmk](https://www.ruby-forum.com/u/rmk)\
**Post date:** [June 25, 2010, 4:24pm UTC](https://www.ruby-forum.com/t/rails-models-database-updates-from-outside-rails/190672/4 "2010-06-25T16:24:20Z")

</div>

On Thu, Jun 24, 2010 at 10:00 PM, Radhesh K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> So a daemon goes into the lib directory and can be started whenever  
> Rails starts?

If that’s what you want to do, sure.

> > > Another constraint is that I am using a JRuby-based system.
> 
> I heard that the ‘daemon’ ruby gem works only for MRI and not on  
> JRuby, is that true?

Yes, but googling “jruby daemon process” will get you lots of possible  
alternatives.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan
