求人サイトを作成しています
formで送信された値をデータベースに保存したいのですが、うまくいきません。 助けていただけると幸いです
controller
1class JobsController < ApplicationController 2 before_action :only_recruiter, only: %i(new create update destroy) 3 def show 4 end 5 6 def create 7 @job=Job.new(job_params) 8 if @job.save 9 redirect_to user_path(current_user.id) 10 else 11 redirect_to new_user_job_path(current_user.id) 12 end 13 end 14 15 def index 16 17 end 18 19 def destroy 20 21 end 22 23 def update 24 25 end 26 27 def new 28 @job=Job.new 29 end 30 31 private 32 def only_recruiter 33 if current_user.occupation == "Jobseeker" 34 redirect_to user_path(@current_user.id) 35 end 36 end 37 38 def job_params 39 params.require(:job).permit(:name, :address, :category, :job_info,:qualification, :japanese_level, :learn) 40 end 41end 42 43
formView
1<div class="sign-up-page"> 2 <div class="card"> 3 <div class="card-header"> 4 求人票作成 5 </div> 6 7 <div class="card-body"> 8 <%= form_with model: @job, url: user_jobs_path, local: true do |f| %> 9 10 11 <div class="form-group"> 12 <%= f.text_field :name, autofocus: true, autocomplete: "name", class: "form-control", placeholder: "企業名" %> 13 </div> 14 15 <div class="form-group"> 16 <%= f.text_field :address, class: "form-control", placeholder: "住所" %> 17 </div> 18 19 <div class="form-group"> 20 <P> 業種選択</p> 21 <%= f.select :category, Job.categories.keys.to_a, include_blank: true %> 22 </div> 23 24 25 <div class="form-group"> 26 <%= f.text_area :job_info, class: "form-control", placeholder: "企業概要", rows: "4" %> 27 </div> 28 29 <div class="form-group"> 30 <%= f.text_area :qualification, class: "form-control", placeholder: "求める人材", rows: "4" %> 31 </div> 32 33 <div class="form-group"> 34 <P> 求める日本語レベル</p> 35 <%= f.select :japanese_level, Job.japanese_levels.keys.to_a, include_blank: true %> 36 </div> 37 38 <div class="form-group"> 39 <%= f.text_area :learn, class: "form-control", placeholder: "学べること", rows: "4" %> 40 </div> 41 42 43 <div> 44 <div class="sign-up__submit-btn"> 45 <%= f.submit "募集を開始する(START)", class: "btn btn-block text-white" %> 46 </div> 47 <% end %> 48 </div> 49 50 </div> 51 </div> 52コード
table
1create_table "jobs", force: :cascade do |t| 2 t.bigint "user_id" 3 t.string "name", null: false 4 t.string "address", null: false 5 t.integer "category", default: 0, null: false 6 t.text "job_info" 7 t.text "qualification" 8 t.integer "japanese_level", default: 0, null: false 9 t.text "learn" 10 t.index ["user_id"], name: "index_jobs_on_user_id" 11 end
jobrb
1class Job < ApplicationRecord 2 belongs_to :user 3 4 enum category: { 5 Jobseeker: 0, recruiter: 1 6 } 7 8 enum japanese_level: { 9 good: 0, bad: 1 10 } 11 12 13end
パラメーター
Parameters: {"authenticity_token"=>"yR9hbn9aFcYnFdDmFW0d4hVuZxNA5OMRAzXLgBmGzAyJurlMjxUJyrxGCGRAuJ11jFa2Rw/HFVwOslKhMfvc7A==", "job"=>{"name"=>"aaa", "address"=>"aaa", "category"=>"Jobseeker", "job_info"=>"aaa", "qualification"=>"aaaa", "japanese_level"=>"good", "learn"=>"aaaa"}, "commit"=>"募集を開始する(START)", "user_id"=>"7"}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。