読者です 読者をやめる 読者になる 読者になる

kojiokanoのブログ

コーディング業務で困ったところをまとめています。

本番,stg,devの管理画面のフォームデータをlocalに適応させる方法

メガネさんにフォームのデータをもらう以下サンプル

----------------------------------------------------------------------------------

kja_domain = Domain.find_or_create_by(name: "kaigojob-agent.com", name_stg: "kja-elb-stg-10743901.ap-northeast-1.elb.amazonaws.com")
kja_entry = EntryPoint.find_or_create_by(title: "カイゴジョブエージェント紹介")
kja_exit =ExitPoint.find_or_create_by(title: "申し込む")

Part.create(label: "お名前", input_type: 0, unique_key: "name")
Part.create(label: "電話番号", input_type: 0, unique_key: "tel")
Part.create(label: "法人名", input_type: 0, unique_key: "company")
Part.create(label: "メールアドレス", input_type: 0, unique_key: "email")
Part.create(label: "希望転職時期を教えてください[select]", input_type: 4, unique_key: "when_to_switch_jobs")
Part.create(label: "希望雇用形態を教えてください[select]", input_type: 4, unique_key: "type_of_employment")
Part.create(label: "保有資格", input_type: 1, unique_key: "qualifications_for_care")
Part.create(label: "現在までの転職回数[select]", input_type: 4, unique_key: "the_number_of_job_changes")
Part.create(label: "介護経験年数", input_type: 4, unique_key: "period_of_job_in_care ")
Part.create(label: "現在の業務内容[select]", input_type: 4, unique_key: "job_description")
Part.create(label: "関わりのあるサービスは?[checkbox]", input_type: 1, unique_key: "related_service")
Part.create(label: "興味があるソフトを選択して下さい[checkbox]", input_type: 1, unique_key: "use-soft__check")
Part.create(label: "ご利用中のソフトを教えて下さい[checkbox]", input_type: 1, unique_key: "Interest-soft__check")
Part.create(label: "会員有無", input_type: 2, unique_key: "member__radio")
Part.create(label: "設立期間を選択", input_type: 4, unique_key: "establishment__select")

kja_001 = InquiryForm.create(name: "SF連携_KJA_資格(旧lp_155)", prefix: "kja_001", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)
kja_002 = InquiryForm.create(name: "SF連携_KJA_非公開(旧lp_156)", prefix: "kja_002", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)
kja_003 = InquiryForm.create(name: "SF連携_KJA_高年収(旧lp_157)", prefix: "kja_003", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)
kja_004 = InquiryForm.create(name: "SF連携_KJA_年収UP(旧lp_159)", prefix: "kja_004", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)
kja_005 = InquiryForm.create(name: "SF連携_KJA_施設長(旧lp_857)", prefix: "kja_005", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)
kja_006 = InquiryForm.create(name: "SF連携_KJA_MM(旧lp_858)", prefix: "kja_006", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)
kja_007 = InquiryForm.create(name: "SF連携_KJA_SMS_改善(旧lp_173)", prefix: "kja_007", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)
kja_008 = InquiryForm.create(name: "SF連携_KJA_高待遇(旧lp_176)", prefix: "kja_008", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)
kja_009 = InquiryForm.create(name: "SF連携_KJA_アンケート(旧lp_177)", prefix: "kja_009", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)
kja_010 = InquiryForm.create(name: "SF連携_KJA_介護福祉士(旧lp_179)", prefix: "kja_010", domain_id: kja_domain.id, entry_point_id: kja_entry.id, exit_point_id: kja_exit.id)

kja_forms = [kja_001, kja_002, kja_003, kja_004, kja_005, kja_006, kja_007, kja_008, kja_009, kja_010]

# kja_001_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]
# kja_002_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]
# kja_003_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]
# kja_004_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]
# kja_005_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]
# kja_006_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]
# kja_007_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]
# kja_008_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]
# kja_009_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]
# kja_010_parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]

parts_key = ["qualifications_for_care", "period_of_job_in_care ", "type_of_employment", "when_to_switch_jobs", "job_description", "the_number_of_job_changes"]

kja_forms.each do |form_obj|
parts_key.each.with_index do |key, index|
form_obj.form_parts.build(order: index+1, part_id: Part.find_by_unique_key(key).id).save
end
end

# kja_001.form_parts.build(order: 1, part_id: Part.find_by_unique_key('qualifications_for_care').id).save

# 2017/03/07
Part.create(label: "事業運営にあたり興味ある項目", input_type: :text, unique_key: "caremanagement_interest")
Part.create(label: "運営規模", input_type: :text, unique_key: "base_number")
Part.create(label: "介護ソフトのリースが1年以上残っているか?", input_type: :text, unique_key: "caresoft_lease_year")
Part.create(label: "利用中のソフト名", input_type: :text, unique_key: "caresoft_inuse")
Part.create(label: "立場を教えてください", input_type: :checkbox, unique_key: "customer_position")
Part.create(label: "関わりのあるサービスは?", input_type: :checkbox, unique_key: "careservice_type")
Part.create(label: "開業時期", input_type: :selectbox, unique_key: "establishment_year")

biz_001 = InquiryForm.create(name: "SFA連携_処遇改善加算LP", prefix: "biz_001", domain_id: 1, entry_point_id: 1, exit_point_id: 1)

parts_key = %w(customer_position careservice_type name tel company email caremanagement_interest base_number establishment_year caresoft_inuse caresoft_lease_year)

parts_key.each.with_index do |key, index|
biz_001.form_parts.build(order: index+1, part_id: Part.find_by_unique_key(key).id).save
end

https://bm-sms.slack.com/files/nashiro/F4FMJVD19/db_seed_rb.js

----------------------------------------------------------------------------------

 

↑をseeds.rbにコピペする

 

seeds.rbの以下↓をコメントアウトする

----------------------------------------------------------------------------------

テストデータ用
customer_list = []
500.times do |i|
customer_list << Customer.new(name: "test_data_2000k_#{i}", tel: "090200101#{i}", email: "test_data_2000k_#{i}@example.com", company: "test_data_2000k_#{i}company")
end

----------------------------------------------------------------------------------

 

 ↓のコマンドを打ちフォーム内容を管理システムに反映させる。

 

 

bundle exec rake db:seed

 

うまくいけば何も表示されない

1回だけ叩くようにする(23回連続で叩いてはいけない)