Reputation: 2199
I'm new to Rails and I'm building a front-end for a system automation tool that's written in Perl. I've got the app built and all of the routes are working. I'm using back-ticks to run the Perl commands and then return standard output. I have a single action that runs via a controller (Node -> Bootstrap).
My route looks like this:
http://localhost:3000/nodes/1/bootstrap
Th method bootstrap is called for this route which in turn runs a series of Perl/shell commands wrapped in logic to ensure that the process is completed.
My problem is that the HTML page that is generated is static while my process is multi-step. I need a way of displaying the progress of the steps and their associated output.
What's the simplest way of refreshing/redirecting to display the multiple steps together initiated from a single route?
Upvotes: 0
Views: 136
Reputation: 6096
I don't think that what you're asking is possible within a single route/controller action.
A simplified control flow would look like this:
routes.rb
to figure out which controller and action to pass the request to.If you want to make your page more 'dynamic' then your only real option is to use Javascript to modify the page's HTML client-side after it's already been output to the user. What you're asking is actually a pretty complicated task and could be daunting for a beginner.
Personally I'd do something like moving the backticked_code_that_runs_the_perl_script
from the controller to a background job, which you then queue using ActiveJob. Then on the front-end I'd write some Javascript which repeatedly polls your background job to get its status, and updates the DOM accordingly.
That's a very high-level description but I hope it helps you get started!
(Note that ActiveJob wasn't added until Rails 4.1 or 4.2, I forget. If you're using an earlier version of Rails it won't be available and you'll have to use one of the job runners like Resque by itself)
Upvotes: 1