0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

問合フォーム作成に挑戦中

Posted at

業務改善のために作ってみたいアプリ
 法律事務所特有の利害関係確認機能付きの問合せフォームが欲しい…

そこで、学習の備忘録として不束メモ

% rails new contact

少し時間がかかった後にディレクトリ間違ったなと後悔…

% cd contact

gemfile に連携したいキントーンをこのように

gem 'kintone'

記載して、bundle install。お次は問合コントローラー作成

% rails generate controller inquiries

app/config/routes.rbに

Rails.application.routes.draw do
  
  get '/inquiries', to: 'inquiries#new' #キントーン連携用に
  post '/inquiries', to: 'inquiries#create' # kintone連携用に
  resources :inquiries  #7つのアクション使える
  root 'inquiries#new'  #top_page
end

と記載。 HPからの編集もしたければ、editのフィールドコード作成すればいけるのかしら??試す時間作れたら更新しよう‼︎
HPのマイページからデータ添付できたらいいもの!
でも、営業妨害きたら嫌だなww

残りカタカタ問合せフォームを打ち込みながら
郵便番号から住所反映させたいこと、ユーザー管理機能ほしいこと、選択式プルダウン入れたいことに思いだし,
下記追加したいが、不具合でないか心配なのでdeviseのみbundle install.

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

その後、kintone連携のためのアプリ作成し、
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
 

これでいけるか…
あぁ…viewがエラー
続きは後日

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?