You don't have to redirect back to the original page (in fact, the URL hasn't changed, so redirecting doesn't make sense). Instead, you render the same template. Simply insert erb :'index.html'
in the second block (post '/'
) as well, and put the URLs in a class variable, so that they will be available to the template:
@urls=params[:urls].split
(The split
is there so you get an array of strings, rather than one long string with linebreaks.)
Finally, you add some logic to the template to check whether there are any URLs to display, and if so render them as a list:
<% if @urls && !@urls.empty? %>
<h1>URLs</h1>
<ul>
<% for @url in @urls %>
<li>
<%= @url %>
</li>
<% end %>
</ul>
<% end %>
<h1>Enter URLs Below </h1>
...etc...