Rails plain text template

LandonSchropp picture LandonSchropp · Jul 18, 2014 · Viewed 6.9k times · Source

I'd like to render an ERB template into plain text in Rails. Ideally, I'd be able to do something like this:

app/views/test/test.txt.erb

Test
<%= @test %>

When I tried, Rails complained with the following error:

ActionView::MissingTemplate (Missing template test/test, application/test with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee]}. Searched in:
  * "/Users/landonschropp/Development/test/app/views"
):

Answer

infused picture infused · Jul 18, 2014

The easiest way is in your action:

render '/test/test.text.erb', layout: false, content_type: 'text/plain'