Bra*_*ird 6 ruby model-view-controller ruby-on-rails sendgrid griddler
我正在使用Sendgrid Parse API和Griddler gem接收传入的电子邮件.在大多数情况下,这很好用; 但是,如果您没有使用状态代码200响应Sendgrid,他们将认为应用程序没有正确接收POST请求并继续尝试发布3天的POST.我正在尝试回复状态代码并遇到问题.
在常规RESTful路由中,您可以执行类似...
render :status => 200
Run Code Online (Sandbox Code Playgroud)
但是,我相信这必须在控制器中完成以识别渲染方法.Griddler建议您创建一个EmailProcessor模型并使用"进程"方法来处理电子邮件.
据我所知,你不能在模型中使用render方法.因此,我使用类方法创建了一个EmailProcessorsController类,如下所示.
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
Run Code Online (Sandbox Code Playgroud)
以下是我从我的应用程序获得的错误.它不喜欢渲染方法:(
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'
Run Code Online (Sandbox Code Playgroud)
我是一个新的开发者,这可能是简单的东西,但我被卡住了.任何关于问题和设计的想法和评论都非常感谢.谢谢!
UPDATE!
根据@meagar的建议,我将渲染调用移动到控制器,如下所示,但现在我得到了一个不同的错误,我不知道该怎么做.
class EmailProcessorsController < ApplicationController
def initialize(email)
@email = email
@to = email.to # this is an array
@from = email.from
end
def process
# do other stuff
render :status => 200
end
end
Run Code Online (Sandbox Code Playgroud)
没有渲染调用,我没有收到错误.这是我在调用渲染时得到的错误...
Module::DelegationError (ActionController::RackDelegation#status= delegated to @_response.status=, but @_response is nil: #<EmailProcessorsController:0x000001063b1558 @email=#<Griddler::Email:0x00000106378ac8 @params={"headers"=>"Received: by mx-007.sjc1.send
Run Code Online (Sandbox Code Playgroud)
render
是一个实例方法,而不是类方法.您需要实例化控制器的实例,但无论如何都无法实现.
尝试从模型中渲染是一个严重的错误.该模型不知道涉及HTTP请求.您的控制器应该创建模型,调用其上的任何操作,等待成功,然后您的控制器应该呈现响应.你想要做的事情从根本上被打破了.
归档时间: |
|
查看次数: |
4360 次 |
最近记录: |