65 lines
1.5 KiB
Ruby
65 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'google/apis/sheets_v4'
|
|
require 'google/api_client/client_secrets'
|
|
class FormsController < ApplicationController
|
|
before_action :require_login, except: [:form]
|
|
layout 'submission', only: [:form]
|
|
|
|
def new
|
|
@form = current_user.forms.build(backend_name: 'google_sheets')
|
|
end
|
|
|
|
def show
|
|
@form = current_user.forms.find_by!(token: params[:id])
|
|
@pagy, @submissions = pagy(@form.submissions.order(created_at: :desc), items: 25)
|
|
end
|
|
|
|
def index
|
|
@forms = current_user.forms
|
|
redirect_to new_form_url if @forms.empty?
|
|
end
|
|
|
|
def create
|
|
@form = current_user.forms.build(form_params)
|
|
if @form.save
|
|
redirect_to form_url(@form)
|
|
else
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@form = current_user.forms.find_by!(token: params[:id])
|
|
puts "===========#{@form.notify_email}======================="
|
|
end
|
|
|
|
def notification
|
|
puts ''
|
|
@form = current_user.forms.find_by!(token: params[:id])
|
|
end
|
|
|
|
def update
|
|
@form = current_user.forms.find_by!(token: params[:id])
|
|
if @form.update(form_params)
|
|
redirect_to form_url(@form)
|
|
else
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def setup
|
|
@form = current_user.forms.find_by!(token: params[:id])
|
|
end
|
|
|
|
def form
|
|
@form = Form.find_by!(token: params[:id])
|
|
end
|
|
|
|
private
|
|
|
|
def form_params
|
|
params.require(:form).permit(:title, :thank_you_url, :backend_name, :google_spreadsheet_sheet, :airtable_table, :airtable_api_key, :airtable_app_key, :notify_email)
|
|
end
|
|
end
|