Reputation: 6180
I am working on a ruby on rails application. I need data displayed on a page to be exported in a .text file format like below:
The format of the file is
# category name
## question
answer
## question
answer
# another category
## question
answer
...
In the index view(whose contents I want to export) I have:
<% @categories.each do |category| %>
<h4><%= category.name %> Category</h4>
<ol>
<% category.questions.each do |question| %>
<li><%= question.content %></li>
<ul>
<% question.answers.each do |answer| %>
<li><%= answer.content %></li>
<% end %>
</ul>
<% end %>
</ol>
<% end %>
How can I do this?
Upvotes: 0
Views: 282
Reputation: 1144
Create a new view file eg. categories/index.text.erb Add your each loop there, remove all the HTML tags, format it the way you need then start your app and go localhost:3000/categories.text You can save the output with your browser. You can still access the HTML version of the page at /categories
Upvotes: 1