Create an inquiry form with the Ruby SDK

Introduction

There are many cases where inquiries and contact forms are configured and managed on a company's website. This article introduces how to manage these inquiries using the Kintone REST API client for Ruby, from an inquiry form on a website created with Ruby on Rails.

(Note: The SDK introduced in this article is a 3rd party SDK. Check the licenses, functions, etc. before using.)

Setting Up the Help Desk Management App

Step 1

Navigate to the Help Desk Management App and click the gear icon to access the App settings.

Add a Text field to the form for the Company name. Then update the field title and field code for each field in the form to match the table below.

Field Type

Field Name

Field Code

Text

Company

Company

Text

Name

Customer_name

Radio Button

Inquiry Type

QType

Text Area

Details

Detail

Step 2

Next, open the App Settings tab and click API Token under Customization and Integration.

Click the Generate button and check Add records. Then save the settings.Make a note of the generated API token, as it will be necessary later for the customization code. Also make a note the App ID (in the following sample application, the App ID is 272).

Finally, to apply the App settings, click the Update App button.

Settings for the Help Desk Management App are now complete.

Creating an Inquiry Form

Step 1

Next, make an inquiry form application with Ruby on Rails.(For those without a development environment for Ruby on Rails, refer to Getting Started with Rails to set up an environment.)

Open the terminal and execute the following command.

This creates a Rails application called contact.As the subsequent commands are executed in the created contact directory, move to the directory with the following command.

Step 2

Step 3

Create a controller with the following command. As an example, the controller is named inquiries.

Step 4

Next, open the routes.rb file in the config folder and edit it to match the following coding.

Code description

The routing within the above code is defined as follows to create the inquiry form.

HTTP method

Path

Field Code

Purpose

GET

/inquiries

inquiries#new

Returns an HTML form to create one inquiry

POST

/inquiries

inquiries#create

Creates one inquiry

The resource name specifies the inquiries created earlier.

The code also sets a form for creating an inquiry on the homepage.

Step 5

Create a new.html.erb file in the inquiries folder under the views folder.

Using the following code in the newly created new.html.erb file, create an inquiry form by using FormBuilder.

The following form should be generated.

Step 6

Generate a model of the resource name specified earlier.Run the following command to generate the inquiry model.

This generates the following model.

Field Name

Field Type

company_name

string

client_name

string

contact_type

string

details

text

Execute migration with the following command to create a table in the database.

An Inquiries table is now created in the database.In this case, the default database sqlite 3 was used. If sqlite 3 has not been installed yet, execute the following command to install it.

Step 7

Edit the controller created earlier.Open inquiries_controller.rb in the controllers folder with an editor.

Copy and paste the following code into the inquiries_controller.rb file. Replace the {subdomain}, {API Token}, and {App ID} in lines 17 and 18 with the name of the Kintone subdomain, the API token of the App, and the App ID.

Code description

For the sake of simplicity, only the new and create actions of the controller are defined.The inquiry form is displayed with the new method (as there is no processing in particular, the method is blank) and the input data is saved with the create method.

After saving the form data in the database, the data is registered into the Kintone App.

The record data is set using Hashes, and is registered into the Kintone App via REST API.

Testing the Script

Start the local Rails server with the following command.

Accessing http://localhost:3000 through the browser will display the following inquiry form.Enter in data and click the Send button to add a new record to Kintone.

Finally

Many websites are created with Ruby on Rails when collecting external data such as inquiry forms, contacts, questionnaires, etc. When managing these systems with Kintone, the Kintone REST API client for Ruby introduced here is very useful.