简体   繁体   English

将原始html写入Rails中的响应对象(使用ActionDispatcher :: Response)

[英]writing raw html to a response object in rails (using ActionDispatcher::Response)

How to write the response from the controller using the ActionDispatch::Response object. 如何使用ActionDispatch :: Response对象编写来自控制器的响应。 There seems to be no api that does http://api.rubyonrails.org/classes/ActionDispatch/Response.html . 似乎没有可以执行http://api.rubyonrails.org/classes/ActionDispatch/Response.html的 api。

The below code works which does not use any view. 下面的代码有效,不使用任何视图。 Is the same can be achived using a response object. 使用响应对象可以实现相同的效果。 The reason being having a necessity to write some binary data to html(which is required for the the current rails app being written) 原因是必须将一些二进制数据写入html(当前正在写入的Rails应用程序需要此数据)

class HelloController < ApplicationController
  def index
    render :text => "hello" # want to use ActionDispatch::Response object instead of this
  end
end

Have you taken a look at send_data ? 您看过send_data吗? It may be what you're looking for. 这可能是您要寻找的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM