Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails plain text template

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"
):
like image 956
LandonSchropp Avatar asked Jul 18 '14 04:07

LandonSchropp


1 Answers

The easiest way is in your action:

render '/test/test.text.erb', layout: false, content_type: 'text/plain'
like image 89
infused Avatar answered Oct 15 '22 19:10

infused