mercredi 1 octobre 2014

Undefined method render in Rails controller - Trying to respond to Sendgrid with a 200 status code


Vote count:

0




I'm using the Sendgrid Parse API along with the Griddler gem to accept incoming emails. For the most part, this works fine; however, if you don't respond to Sendgrid with a status code 200, they will assume that the app didn't correctly receive the POST request and keep trying to make a POST for 3 days. I'm trying to respond with a status code and am having issues.


In regular RESTful routes, you can do something like...



render :status => 200


However, this must be done in a controller to recognize the render method, I believe. Griddler suggests that you create an EmailProcessor model and use a 'process' method to deal with the email.


From what I understand, you can't use the render method in models. So, I created an EmailProcessorsController class with a class method as seen below.



class EmailProcessor < ActiveRecord::Base

include ApplicationHelper

def initialize(email)
@email = email
@to = email.to # this is an array
@from = email.from
end

def process
# do other stuff
EmailProcessorsController.render_ok
end
end

class EmailProcessorsController < ActionController::Base

def self.render_ok
render :status => 200
end
end


Below is the error I get from my app. It doesn't like the render method :(



NoMethodError (undefined method `render' for EmailProcessorsController:Class):
app/controllers/email_processors_controller.rb:6:in `render_ok'
app/models/email_processor.rb:16:in `process'


I'm a newer dev and this probably something uber simple, but I'm stuck. Any thoughts and comments on the problem as well as design are greatly appreciated. Thanks!



asked 36 secs ago







Undefined method render in Rails controller - Trying to respond to Sendgrid with a 200 status code

Aucun commentaire:

Enregistrer un commentaire