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"
):
The easiest way is in your action:
render '/test/test.text.erb', layout: false, content_type: 'text/plain'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With