I'm trying to set up my RoR 3 application to receive emails and then process those emails and insert them into the database.
In my application, I have a "jobs" controller. Users can create jobs. I also have a "comments" controller. Users can create comments on jobs.
Here is (part of) what I have in my comments controller:
def new @job = Job.find(params[:job_id]) @comment = @job.comments.build end def create @job = Job.find(params[:job_id]) @comment = @job.comments.build(params[:comment]) @comment.user_id = current_user.id @comment.commenter = current_user.login if @comment.save redirect_to @job else render :action => "new" end end
When users add a comment, the admin receives an email. When admins add a comment, users receive an email. (This is already functioning.)
class IncomingMailsController < ApplicationController require 'mail' skip_before_filter :verify_authenticity_token def create another_comment = Comment.create(:title => params[:subject], :body => params[:plain]) render :text => 'success', :status => 200 #status of 404 rejects mail end end
Looking at the above comment controller, it looks like I'll need the job_id, current_user.id, and current_user.login.
Here's what I am having trouble sorting out: what goes in my "incoming_mails" controller? How can I make sure that when a user responds via email that the controller in "incoming_mails" is able to find the job_id and the current_user.id (or user_id) and then insert that information into the database?
I'm thinking that I'll need to grab the user's email address and then also have the job_id in the subject line...hmmm....
Does anyone have experience setting up incoming mail processing in Rails 3?