Ruby on rails 错误:";内部服务器错误:未定义的方法“发送数据”;
我试图在ApplicationController中调用send_data,然后出现错误Ruby on rails 错误:";内部服务器错误:未定义的方法“发送数据”;,ruby-on-rails,ruby,actioncontroller,grape-api,Ruby On Rails,Ruby,Actioncontroller,Grape Api,我试图在ApplicationController中调用send_data,然后出现错误 error: "Internal server error: undefined method `send_data' 此处提供了环境版本:ruby 2.1.2p95/angularjs 1.2 许多人建议您只能在ApplicationController中调用send_data,并讨论如何向这样的外部类公开Application Controller方法。 但我在ApplicationContro
error: "Internal server error: undefined method `send_data'
此处提供了环境版本:ruby 2.1.2p95/angularjs 1.2
许多人建议您只能在ApplicationController中调用send_data,并讨论如何向这样的外部类公开Application Controller方法。
但我在ApplicationController中调用send_数据
# Application controller
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
# protect_from_forgery with: :null_session
include ApplicationHelper
def self.send_csv(csv, options = {})
Rails.logger.debug("send_csv")
bom = " "
bom.setbyte(0, 0xEF)
bom.setbyte(1, 0xBB)
bom.setbyte(2, 0xBF)
Rails.logger.debug("send_data start")
send_data bom + csv.to_s, options
end
end
[致电]
class ApplicationController < ActionController::Base
include ApplicationHelper
# def self.send_csv(csv, options = {})
def send_csv(csv, options = {})
Rails.logger.debug("not self send_csv")
bom = " "
bom.setbyte(0, 0xEF)
bom.setbyte(1, 0xBB)
bom.setbyte(2, 0xBF)
Rails.logger.debug("send_data start")
send_data bom + csv.to_s, options
end
如何从Grape实例调用应用程序控制器中的实例方法
我感谢你的帮助 对不起,我不知道Grape是如何工作的,所以我不知道如何使用
发送数据
来实现此功能。谢谢!在你的帮助下,我想出了另一种方法!如果你找到了解决方案,你可以回答自己的问题。
class ApplicationController < ActionController::Base
include ApplicationHelper
# def self.send_csv(csv, options = {})
def send_csv(csv, options = {})
Rails.logger.debug("not self send_csv")
bom = " "
bom.setbyte(0, 0xEF)
bom.setbyte(1, 0xBB)
bom.setbyte(2, 0xBF)
Rails.logger.debug("send_data start")
send_data bom + csv.to_s, options
end
error: "Internal server error: undefined method `send_csv' for ApplicationController:Class"