[RUBY] Challenge to create inquiry form

An app you want to make to improve your business I want an inquiry form with a law firm's unique interest confirmation function ...

Therefore, as a memorandum of learning

% rails new contact

After a while, I regret that the directory was wrong ...

% cd contact

Kintone that you want to link to gemfile like this

gem 'kintone'

Describe and bundle install. Next is inquiry controller creation

% rails generate controller inquiries

in app/config/routes.rb

Rails.application.routes.draw do
  
  get '/inquiries', to: 'inquiries#new' #For Kintone cooperation
  post '/inquiries', to: 'inquiries#create' #For kintone cooperation
  resources :inquiries  #7 actions can be used
  root 'inquiries#new'  #top_page
end

Described as. If you want to edit from HP, can you create an edit field code? ?? Let's update when we have time to try it! ︎ I wish I could attach data from my page on HP! But I don't want to interfere with business ww

While typing in the remaining rattling inquiry form I want to reflect the address from the zip code, I want the user management function, I want to put in a selectable pull-down, I want to add the following, but I am worried that it is not a problem, so only devise bundle install.

gem 'active_hash'
gem 'jp_prefecture'
gem 'jquery-rails'
gem 'devise'

After that, I created an app for kintone cooperation, app>controllers>inquiries_controller.rb



require 'kintone'
class InquiriesController < ApplicationController

  def new
  end

  def create
    @user = User.new(inquiry_params)
    if @user.save
      # Use token authentication
      api = Kintone::Api.new("subdmain.cybozu.com", "APItoken")
      app = appId

      # Record register(single record)
      # Use Hash
      record = {"company" => {"value" => inquiry_params[:company]},
                "last_name" => {"value" => inquiry_params[:last_name]},
                "first_name" => {"value" => inquiry_params[:first_name]},
                "kana_last_name" => {"value" => inquiry_params[:kana_last_name]},
                "kana_first_name" => {"value" => inquiry_params[:kana_first_name]},
                "email" => {"value" => inquiry_params[:email]},
                "phone_number" => {"value" => inquiry_params[:phone_number]},
                "postal_code" => {"value" => inquiry_params[:postal_code]},
                "prefecture" => {"value" => inquiry_params[:prefecture]},
                "city" => {"value" => inquiry_params[:city]},
                "street" => {"value" => inquiry_params[:street]},
                "other" => {"other" => inquiry_params[:other]}
                }
      api.record.register(app, record)
      redirect_to root_path
    else
      render 'new'
    end
  end
  
  private
    def inquiry_params
      params.require(:user).permit(:company,
        :last_name, 
        :first_name, 
        :kana_last_name, 
        :kana_first_name,
        :email,
        :phone_number,
        :postal_code,
        :prefecture, 
        :city,  
        :street, 
        :other
        )
    end
end
 

Can I go with this ... Ah ... view has an error More on that later

Recommended Posts

Challenge to create inquiry form
How to create docker-compose
Reasons to include ActiveModel :: Model to create a Form object
How to create an application
Easy to create Processing library
How to create a form to select a date from the calendar
I want to create a form to select the [Rails] category
How to create a method
[Rails 6] How to create a dynamic form input screen using cocoon
Preparing to create a Rails application
Dare to challenge Kaggle with Java (1)
[Java] How to create a folder
Try to create a server-client app
Challenge to install WSL2 and docker
Java adds form fields to PDF