Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I go about displaying this information in rails?
    text
    copied!<p>I'm trying to make a rails app that tests some ports of a hostname I provide. This is what I have so far:</p> <p>routes.rb:</p> <pre><code>Diagnostics::Application.routes.draw do match 'port_testing/test', :controller =&gt; :port_testing, :action=&gt; :test end </code></pre> <p>index.html.haml:</p> <pre><code>= stylesheet_link_tag 'user' .spacey %h1 Port Testing = form_tag('port_testing/test', method: 'get') do = text_field_tag :hostname, 'localhost', size: 50 - @models.each do |key,value| %input{:type=&gt;"checkbox", :name=&gt;"#{key}", :value=&gt;1, :checked=&gt;value} =key %input{:type =&gt; :submit, :value =&gt; "Test"} </code></pre> <p>port_testing_controller.rb:</p> <pre><code>require 'socket' class PortTestingController &lt; ApplicationController def index @models = {"80" =&gt; false, "443" =&gt; false, "2195" =&gt; true, "28009" =&gt; false} end def test puts "\n" hostname = params["hostname"] puts hostname ports = ["80", "443", "2195", "28009"] ports.each do |key| #puts key if params.has_key?(key) port = key.to_i is_port_open?(hostname, port) end end redirect_to("#/port_testing") end def is_port_open?(ip, port) begin Timeout::timeout(1) do begin s = TCPSocket.new(ip, port) puts "Successful" s.close return true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH puts "Error" return false end end rescue Timeout::Error puts "Timeout" end return false end end </code></pre> <p>Right now, what I have works. I can put in a hostname in the text field, check which ports I want tested, and I get the results printed to the screen. </p> <p>However, what I would like to do is to be able to save the most recent parameters I entered. Right now, after I click test, the page reloads so it resets to the default hostname and the default port. I would like it to keep the same hostname and port as I had before. How would I do this?</p> <p>Also, I would like to have the results be put in a table and displayed on the same webpage. How would I go about doing this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload