To begin, ensure you have added the necessary gems to your Gemfile
by including 'ruby-plsql' and 'haml':
gem 'ruby-plsql'
gem 'haml'
Next, generate a controller and its components using the Rails generator:
rails generate controller procedure execute
In the config/routes
file, update the route from get
to post
:
get 'procedure.execute'
post 'procedure/execute'
Create a simple view using HAML by adding the following code to
app/views/procedure/execute.html.haml
:
%div
%p#notice
= "A stored procedure is currently running. Please wait..." if @is_running
%div
= field_set_tag "Procedure 1" do
= form_tag procedure_execute_path, id: "form1" do
= hidden_field_tag "proc", "stored_proc_1"
= text_field_tag "date1", nil
= text_field_tag "date2", nil
= submit_tag "Execute", disabled: @is_running
%div
= field_set_tag "Procedure 2" do
= form_tag procedure_execute_path, id: "form2" do
= hidden_field_tag "proc", "stored_proc_2"
= text_field_tag "string1", nil
= text_field_tag "number1", nil
= submit_tag "Execute", disabled: @is_running
%div#results
= @results if @results
%script
$(document).on("ready", register_ajax);
$(document).on("page:change", register_ajax);
Ensure that jQuery and Unobtrusive Javascript support are included in
/app/assets/javascripts/application.js
:
//= require jquery
//= require jquery_ujs
Check that your config/application.rb
contains this line within the Application class:
config.assets.enable = true
The next step involves adding Ajax code for submitting forms asynchronously and handling results to the
/app/assets/javascripts/procedure.js
file:
var ajax_registered = false;
function register_ajax() {
// Code for registering Ajax calls
}
Lastly, implement the execute
action in the ProcedureController
located at
app/controllers/procedure_controller.rb
:
class ProcedureController < ApplicationController
// Code for executing stored procedures
end
With everything set up, you can now handle stored procedures asynchronously and customize the view to fit your needs. This structured approach provides a foundation for future enhancements and refinements.