Philip Hallstrom wrote:
>> from my ruby daemon, into my rails app as a Model and save to  
>> database?

Thanks for the reply!  I guess I just want to make sure that this works 
and is a good way to do it.  Here is what I have in my daemon below:
==================


require 'rubygems'
require 'robustthread'
require 'tmail'
require 'activerecord'

conf = YAML::load(File.open(File.dirname(__FILE__) + 
'/var/www/rails/somedomain/current/config/database.yml'))
ActiveRecord::Base.establish_connection(conf[environment])

RobustThread.logger = Logger.new( 'somedomain_mail.log' )
RobustThread.exception_handler do | exception |
  email_me_the_exception( exception )
end

pid = fork do
  RobustThread.loop( :seconds => 30, :label => "Processing emails..." ) 
do
  #check for emails in the maildir
  Dir["/home/nate/Maildir/new/**/**"].each do | thisfile |

    mail = TMail::Mail.load( thisfile )
    @subject = mail.subject
    @wr_token = mail.to.first.gsub(/[[email protected]]/, '')
    @body = mail.body.gsub(/\/\/ Add your reply above here.*$/m, '')

    @user = User.find_by_email(mail.from, :select => :id)
    @work_request = WorkRequest.find_by_access_token(@wr_token, :select 
=> :id)
    @log_item = LogItem.new(
      :user_id => @user.id,
      :work_request_id => @work_request.id,
      :comment_textile => @body
    )
    if @log_item.save
      bla...
    else
      bla...
    end

  end
end
sleep
end
Process.detach pid

class LogItem < ActiveRecord::Base
end

class User < ActiveRecord::Base
end

class WorkRequest < ActiveRecord::Base
end
-- 
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to