What is the best way to invoke a PLSQL function in Rails, through a view's button click?

I am facing a challenge in my Rails project that I, as a beginner, am struggling to overcome. The task at hand is to create a dashboard page within the existing web application built on Rails. This dashboard should have the ability to trigger PLSQL procedures on an Oracle server by providing two dates and clicking a button.

My attempt involved using the ruby-plsql gem in the rails console, which allowed me to successfully call the desired Oracle stored procedure.

My objective now is to design a view with a form that can accept date inputs for the stored procedure, followed by the execution of the procedure upon clicking the submit button. The ruby-plsql method must be invoked upon submission. Moreover, it's crucial to prevent the re-launching of an already running procedure, possibly by disabling the submit button while a procedure is ongoing.

How can this functionality be implemented?

Answer №1

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.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The state value in React useContext remains unchanged when navigating between pages

Currently, I am delving into the useContext hook and experimenting with a shopping cart exercise in Next.js with app router. This exercise involves managing the cart's value globally. However, I encountered an issue when trying to pass the updated ca ...

Transfer PDF file to user's web browser through XMLHttpRequest, utilizing up-to-date HTML5 techniques, all while maintaining the integrity of the document's encoding

I am trying to achieve a similar result as described in this StackOverflow post about handling file download from ajax post. However, I'm working with a dynamically-generated PDF file created using PHP v5.6.10 (with the PDFLib extension, v9.0.5). Unf ...

What is the best way to transform a JSON object into a personalized C# object?

Is there a simple method to populate my C# object with the JSON data received through AJAX? The following is an example of a JSON object passed to a C# web method using JSON.stringify: { "user": { "name": "asdf", ...

Struggling to navigate web pages with Selenium using Java is proving to be a challenge

I am currently working on using Selenium's HtmlUnitDriver and WebElement classes in Java to automate clicking the "Download as CSV" button on Google Trends. The issue that I am encountering is that the button remains hidden until another settings men ...

Utilizing Multiple Checkboxes for Precision Search Refinement

Big thanks to Khalid Ali for the support provided up until now. I am currently working with an array of songs that each have descriptions, keywords, etc. I have a set of checkboxes that I want to use to refine a search. Essentially, if someone selects the ...

What is the process of retrieving data from a Nextjs API route during the build and deployment stages?

I'm currently facing an issue while trying to deploy my nextjs web app on vercel. Upon deployment, I encounter the following error: > Build error occurred FetchError: request to http://localhost:3000/api/products failed, reason: connect ECONNREFUS ...

Tips for choosing elements based on the length of an array

When using an each function, I scan the DOM to find multiple elements with a specific className. Depending on the length of this ClassName, it will create an array that is either 2 or 4 elements long. I need to distinguish between these two types of elem ...

What is the best way to increase a numerical input?

While experimenting with HTML input elements, I decided to utilize the step attribute. This allowed me to increment the current value by 100 when clicking the up or down arrows in the input field. However, I discovered that the step attribute restricts th ...

Creating a jQuery AJAX form that allows users to upload an image, submit the form, and store the entered values in a MySQL database

I am struggling with an HTML form that I am trying to submit using jQuery's $.ajax(); The form needs to: 1. Upload an image to a directory with error checks 2. Save the image path to a MySQL database 3. Insert two other form values (input and select) ...

To trigger a Bootstrap 5 modal in a child component from a button click in the parent component in Angular without the need to install ng-bootstrap is possible with the following approach

To achieve the functionality of opening a modal in a child component upon clicking a button in the parent component without using ngx-bootstrap due to restrictions, one approach is to add data-bs-target and data-bs-toggle attributes to the button. Addition ...

Showcase a Pair of Files Next to Eachother using HTML

I am a beginner with HTML and I am trying to accomplish a seemingly simple task. I have searched for similar questions and attempted the solutions provided, but none have worked for me. My goal is to have two documents displayed side by side on a web page ...

Make sure to close any existing Featherlight windows before trying to open another one

I'm setting up multiple featherlight instances when the page loads jQuery('.feedback').featherlight(jQuery( "#feedback-box" ), { closeIcon: 'close'}); jQuery('#imprint').featherlight(jQuery( "#imprint-box" ), { closeIcon ...

Download data in CSV, Excel, PDF file types using AngularJS

I need to incorporate functionality in my app that allows users to export table data in CSV, Excel, and PDF formats. My app is being developed using angularjs 1.2.16. Exporting data to Excel To export the table to XLS format, I have included the followi ...

Experiencing a "non-serializable value found in the state" error specifically while utilizing redux toolkit, but this issue does not occur with traditional redux implementations

While transitioning my app to utilize Redux Toolkit, I encountered an error after switching over from createStore to configureStore: A non-serializable value was found in the state at path: `varietals.red.0`. Value:, Varietal { "color": "red", "id": " ...

Incorrect order in Angular2 NgFor within tree model when elements are removed and then added back

Currently experimenting with Angular 2 alpha version 44. Working with a tree model that utilizes recursion for display purposes. Each group contains 'Criterions', 'Segments', and other 'Groups'. Elements can be added or delet ...

Is it possible for JsDoc to help me distinguish between milliseconds and seconds when I inadvertently confuse them?

Exploring TypeScript and JsDoc has been on my to-do list. Occasionally, I find myself mixing numeric values that aren't quite compatible. Let's consider a hypothetical situation where I mix milliseconds and seconds. In the script below, I've ...

Multiple jQuery AJAX requests triggered in a click event handler

I am in the process of developing a PHP web application and utilizing the datatables jQuery plugin along with jQuery AJAX calls to create a dynamic table for editing, deleting, and adding elements. Although it appears to be working correctly, I've not ...

Unable to locate element using document.getElementById in ASP.NET form

Currently, I am working on a project to create an ASP.NET webforms page that will showcase a Google map using the Google Maps JavaScript API with multiple markers. Everything is functioning smoothly as long as I don't place <div id="map-canvas"> ...

Getting an error when trying to call a C# method from JavaScript

Recently, I have been attempting to execute a C# method from JavaScript within my ASP.NET page named parameters.aspx. However, each time I hit the button to trigger the method, an error 404 is displayed. Let's take a look at the C# method defined in ...

Tips for improving php/mysql/ajax performance with heavy reads/writes

When developing a web application that deals with high volumes of reads and writes, especially in scenarios like online gaming where transactions involve money, there are certain things that should be avoided. For instance, having a JavaScript constantly ...