这是我从服务器的跟踪。 似乎POST params与我的employment_applications参数不匹配。 POST电子邮件是' joeacrocetta@gmail.com' 并且select语句是WHERE" employment_applications"。" email" IS NULL
我想我的名字不正确。 我只需要第二组眼睛进行审查。
Started POST "/careers" for ::1 at 2014-12-12 09:58:42 -0500
Processing by EmploymentApplicationsController#create as HTML
Parameters: {"utf8"=>"✓","authenticity_token"=>"xFsoNoiLDuH50WyMfWKdILb+TfUTyBODXEEqqSaFGm+JjNOGF3hSMnJGZnkxS2HUZSO8XtZQ48+XCqa+/uF1+Q==", "employment_application"=>{"name"=>"Joe Crocetta", "date_at(1i)"=>"2014", "date_at(2i)"=>"12", "date_at(3i)"=>"12", "address"=>"filtered", "address_apt_or_floor"=>"", "city"=>"Hoboken", "state"=>"NJ", "zip_code"=>"07030", "home_phone"=>"201-238-2651", "cell_phone"=>"", "email"=>"joeacrocetta@gmail.com", "private_message"=>"", "citizen"=>"true", "authorized"=>"false", "worked_before"=>"false", "convicted"=>"false", "agree_legal_1"=>"true", "agree_legal_2"=>"true", "high_school"=>"", "hs_city"=>"", "hs_state"=>"", "hs_start_at(1i)"=>"2014", "hs_start_at(2i)"=>"12", "hs_start_at(3i)"=>"1", "hs_end_at(1i)"=>"2014", "hs_end_at(2i)"=>"12", "hs_end_at(3i)"=>"1", "hs_graduate"=>"false", "hs_diploma"=>"false", "university"=>"", "university_city"=>"", "university_state"=>"", "university_start_at(1i)"=>"2014", "university_start_at(2i)"=>"12", "university_start_at(3i)"=>"1", "university_end_at(1i)"=>"2014", "university_end_at(2i)"=>"12", "university_end_at(3i)"=>"1", "university_graduate"=>"false", "university_degree"=>"", "vocational_school"=>"", "vocational_city"=>"", "vocational_state"=>"", "vocational_start_at(1i)"=>"2014", "vocational_start_at(2i)"=>"12", "vocational_start_at(3i)"=>"1", "vocational_end_at(1i)"=>"2014", "vocational_end_at(2i)"=>"12", "vocational_end_at(3i)"=>"1", "vocational_graduate"=>"false", "vocational_certifications"=>"", "company"=>"", "company_city"=>"", "company_state"=>"", "company_supervisor"=>"", "company_phone"=>"", "company_job_title"=>"", "company_start_at(1i)"=>"2014", "company_start_at(2i)"=>"12", "company_start_at(3i)"=>"1", "company_end_at(1i)"=>"2014", "company_end_at(2i)"=>"12", "company_end_at(3i)"=>"1", "company_start_salary"=>"", "company_end_salary"=>"", "company_duties"=>"", "company_still_employed"=>"false", "company_may_we_contact"=>"false", "company2"=>"", "company2_city"=>"", "company2_state"=>"", "company2_supervisor"=>"", "company2_phone"=>"", "company2_job_title"=>"", "company2_start_at(1i)"=>"2014", "company2_start_at(2i)"=>"12", "company2_start_at(3i)"=>"1", "company2_end_at(1i)"=>"2014", "company2_end_at(2i)"=>"12", "company2_end_at(3i)"=>"1", "company2_start_salary"=>"", "company2_end_salary"=>"", "company2_duties"=>"", "company2_still_employed"=>"false", "company2_may_we_contact"=>"false", "company3"=>"", "company3_city"=>"", "company3_state"=>"", "company3_supervisor"=>"", "company3_phone"=>"", "company3_job_title"=>"", "company3_start_at(1i)"=>"2014", "company3_start_at(2i)"=>"12", "company3_start_at(3i)"=>"1", "company3_end_at(1i)"=>"2014", "company3_end_at(2i)"=>"12", "company3_end_at(3i)"=>"1", "company3_start_salary"=>"", "company3_end_salary"=>"", "company3_duties"=>"", "company3_still_employed"=>"false", "company3_may_we_contact"=>"false"}, "employmentapplication"=>{"position_applying_for"=>"1"}, "resume_file"=>"", "commit"=>"I'm done. Submit my online employment application!", "slug"=>"careers"}
(0.1ms) begin transaction
EmploymentApplication Exists (0.1ms) SELECT 1 AS one FROM "employment_applications" WHERE "employment_applications"."email" IS NULL LIMIT 1
(0.0ms) rollback transaction
这是我的数据库迁移,我的模型和我的控制器:
1 class CreateEmploymentApplications < ActiveRecord::Migration
2 def change
3 create_table :employment_applications do |t|
4 t.string :name
5 t.datetime :date_at
6 t.string :position_applying_for
7 t.string :address
8 t.string :address_apt_or_floor
9 t.string :city
10 t.string :state
11 t.string :zip_code
12 t.string :home_phone
13 t.string :cell_phone
14 t.string :email
15 t.boolean :citizen
16 t.boolean :authorized
17 t.boolean :worked_before
18 t.string :worked_when
19 t.boolean :convicted
20
21 t.string :private_message
22 t.boolean :agree_legal_1
23 t.boolean :agree_legal_2
24
25 t.string :high_school
26 t.string :hs_city
27 t.string :hs_state
28 t.datetime :hs_start_at
29 t.datetime :hs_end_at
30 t.boolean :hs_graduate
31 t.boolean :hs_diploma
.... etc.
1 class EmploymentApplication < ActiveRecord::Base
2 attr_accessor :name, :email, :date_at, :position_applying_for, :address, :address_apt_or_floor, :city, :state, :zip_code, :home_phone, :cell_phone, :email, :citizen,
3 :authorized, :worked_before, :worked_when, :convicted, :private_message, :agree_legal_1, :agree_legal_2, :high_school, :hs_city, :hs_state, :hs_start_at, :hs_end_at,
4 :hs_graduate, :hs_diploma, :university, :university_city, :university_state, :university_start_at, :university_end_at, :university_graduate, :university_degree,.
5 :vocational_school, :vocational_city, :vocational_state, :vocational_start_at, :vocational_end_at, :vocational_graduate, :vocational_certifications,
6 :company, :company_city, :company_state, :company_phone, :company_supervisor, :company_job_title, :company_start_at, :company_end_at, :company_start_salary, :company_end_salary,
7 :company_duties, :company_still_employed, :company_may_we_contact, :company2, :company2_city, :company2_state, :company2_phone, :company2_supervisor, :company2_job_title,
8 :company2_start_at, :company2_end_at, :company2_start_salary, :company2_end_salary, :company2_duties, :company2_still_employed, :company2_may_we_contact, :company3, :company3_city,
9 :company3_state, :company3_phone, :company3_supervisor, :company3_job_title, :company3_start_at, :company3_end_at, :company3_start_salary, :company3_end_salary, :company3_duties,
10 :company3_still_employed, :company3_may_we_contact
11
12 before_save :downcase_email
13 validates :name, presence: true, length: { maximum: 50 }
14 VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
15 validates :email, length: { maximum: 255 },
16 format: { with: VALID_EMAIL_REGEX },
17 uniqueness: { case_sensitive: false }
18 validates :position_applying_for, :address, :city, :state, :zip_code, :home_phone, presence: true
19
20 # Converts email to all lower-case
21 def downcase_email
22 self.email = email.downcase
23 end
24
25 end
1 class EmploymentApplicationsController < ApplicationController
2 def new
3 @employmentapplication = EmploymentApplication.new
4 end
5
6 def create
7 @employmentapplication = EmploymentApplication.new(employmentapplication_params)
8
9 if @employmentapplication.save
10 upload
11 # @employmentapplication.send_new_applicant_email
12 # @employmentapplication.send_new_applicant_thank_you_email
13 flash[:success] = "Success! Your application is complete and submitted! We will contact you within the next 36 hours."
14 redirect_to root_url
15 else
16 render 'new'
17 end
18 end
19
20 private
21 def employmentapplication_params
22 params.require(:employmentapplication).permit(:name, :email, :date_at, :position_applying_for, :address, :address_apt_or_floor, :city, :state, :zip_code, :home_phone, :cell_phone, :email, :citizen,
23 :authorized, :worked_before, :worked_when, :convicted, :private_message, :agree_legal_1, :agree_legal_2, :high_school, :hs_city, :hs_state, :hs_start_at, :hs_end_at,
24 :hs_graduate, :hs_diploma, :university, :university_city, :university_state, :university_start_at, :university_end_at, :university_graduate, :university_degree,.
25 :vocational_school, :vocational_city, :vocational_state, :vocational_start_at, :vocational_end_at, :vocational_graduate, :vocational_certifications,
26 :company, :company_city, :company_state, :company_phone, :company_supervisor, :company_job_title, :company_start_at, :company_end_at, :company_start_salary, :company_end_salary,
27 :company_duties, :company_still_employed, :company_may_we_contact, :company2, :company2_city, :company2_state, :company2_phone, :company2_supervisor, :company2_job_title,
28 :company2_start_at, :company2_end_at, :company2_start_salary, :company2_end_salary, :company2_duties, :company2_still_employed, :company2_may_we_contact, :company3, :company3_city,
29 :company3_state, :company3_phone, :company3_supervisor, :company3_job_title, :company3_start_at, :company3_end_at, :company3_start_salary, :company3_end_salary, :company3_duties,
30 :company3_still_employed, :company3_may_we_contact)
31 end
32
33 def upload
34 uploaded_io = params[:employmentapplication][:resume_file]
35 File.open(Rails.root.join('public', 'uploads', "resume_#{params[:employmentapplication][:id]}_" + uploaded_io.original_filename), 'wb') do |file|
36 file.write(uploaded_io.read)
37 end
38 end
39 end
抱歉,我不知道如何格式化。
答案 0 :(得分:2)
尝试
params.require(:employmentapplication)
到
params.require(:employment_application)