I have a simple Rails app in which a user submits an integer in a form_tag form, a Ruby script finds the prime factors of the integer, and the output is displayed in a new view. How can I make it so that the output is displayed in the same view as the form instead of a new one?
Here's my current code:
routes.rb:
match '/primes', to: 'programs#primes'
post '/factors', to: 'programs#factors'
primes.html.erb:
<%= form_tag('/factors') do %>
<div class="field">
<p>Enter an integer greater than 1:</p>
<p><%= text_field_tag :number %></p>
</div>
<div class="actions">
<p><%= submit_tag("Find factors") %></p>
</div>
<% end %>
programs_controller.rb:
def factors
n = Integer(params[:number])
.
.
.
# script finds prime factors, stores output in @output
end
factors.html.erb:
<%= @output %>
So what I want the app to do is to render @output in '/primes' instead of routing to '/factors'.