Template error while html rendering in Rails controller action

I am trying to use render html: to render raw html from a controller action:

class SomeController < ApplicationController
  def raw_html
    render html: '<html><body>Some body text</body></html>'
  end
end

However, when I run this controller action, I get a "Template missing" error message

I don't want to use a template, just render raw html.

The error I am getting is:

Processing SomeController # raw_html as HTML Parameters: {} ActionView :: MissingTemplate (missing some_controller / raw_html template with {: locale => [: en] ,: formats => [: html] ,: handlers => [: erb ,: builder ,: raw ,: ruby]}. Search: * "/ Users / doved / source / sample_app / app / views" * "/Users/doved/.rvm/gems/ ruby-2.0.0-p353@syp / gems / chameleon-0.2.4 / app / views "*" /Users/doved/.rvm/gems/ ruby-2.0.0-p353@syp /gems/kaminari-0.15.1/app/views "): app / controllers / some_controller.rb: 14: in call 'raw_html'
lib/middleware/cors_middleware.rb:8:in

I am using Rails 4.0.2

What am I doing wrong?

+4
source share
2 answers
Option

html ​​ render Rails 4.1.

Github

Rails Rails 4.1, html

def raw_html
  render html: '<html><body>Some body text</body></html>'.html_safe ## Add html_safe
end

Rails 4.0.2

def raw_html
  render text: '<html><body>Some body text</body></html>' 
end

: ActionView::MissingTemplate

html render, , html, , Rails some_controller/raw_html .

+4

:

render text: '<html><body>Some body text</body></html>'
+1

Source: https://habr.com/ru/post/1535831/


All Articles