Question

Hey I'm having a problem uploading a file. I'm using carrierwave to upload the file and nested forms to capture the file from the user. When I submit the page everything appears to work but no file is upload nor saved in the database. https://gist.github.com/jpstokes/10276415

Server log

Started POST "/applicants" for 127.0.0.1 at 2014-04-09 10:20:12 -0500
Processing by ApplicantsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"N+hSir8O8GjW3Q6TEgO4i8Yg3id37G/MhJgPuIHbjhQ=",
"applicant"=>{"fname"=>"Jason", "lname"=>"Brown", "phone"=>"555-555-5555",
"alt_phone"=>"555-555-5555", "email"=>"john.doe@abc.com",
"address"=>"123 ABC Lane",       "city"=>"Wonderland", "state"=>"KS", "zip"=>"12345",
"country"=>"United States", "education"=>"High School", "salary"=>"100000", "resumes_attributes"=>
{"0"=>{"name"=>"My resume", "attachment"=>#<ActionDispatch::Http::UploadedFile:0x007fbcceba6cc8
@tempfile=#<Tempfile:/var/folders/4s/z8bwrnjn20b13_w1tw7lnskw0000gn/T/RackMultipart20140409-11899- 
11xnpch>, @original_filename="Document1.docx", @content_type="application/vnd.openxmlformats- 
officedocument.wordprocessingml.document", @headers="Content-Disposition: form-data;    
name=\"applicant[resumes_attributes][0][attachment]\"; filename=\"Document1.docx\"\r\nContent-Type: 
application/vnd.openxmlformats-officedocument.wordprocessingml.document\r\n">}}, "job_id"=>"1"}, 
"skills"=>[{"name"=>"PHP", "last_used"=>"04-12-2012", "years_experience"=>"3"}, {"name"=>"",   
"last_used"=>"", "years_experience"=>""}], "commit"=>"Submit"}
Unpermitted parameters: resumes_attributes, job_id
(0.1ms)  BEGIN
SQL (0.2ms)  INSERT INTO `applicants` (`address`, `alt_phone`, `city`, `country`, `created_at`,   
`education`, `email`, `fname`, `lname`, `phone`, `salary`, `state`, `updated_at`, `zip`) VALUES   
('123 ABC Lane', '555-555-5555', 'Wonderland', 'United States', '2014-04-09 15:20:12', 'High   
School', 'john.doe@abc.com', 'Jason', 'Brown', '555-555-5555', 100000, 'KS', '2014-04-09 15:20:12',     
12345)
(0.1ms)  COMMIT
Skill Load (0.2ms)  SELECT `skills`.* FROM `skills` WHERE `skills`.`name` = 'PHP' LIMIT 1
(0.1ms)  BEGIN
SQL (0.1ms)  INSERT INTO `skill_sets` (`applicant_id`, `created_at`, `last_used`, `skill_id`,   
`updated_at`, `years_experience`) VALUES (294, '2014-04-09 15:20:12', '2012-12-04', 12, '2014-04-09 
15:20:12', 3)
(16.4ms)  COMMIT
Skill Load (0.3ms)  SELECT `skills`.* FROM `skills` WHERE `skills`.`name` = '' LIMIT 1
(0.1ms)  BEGIN
SQL (0.2ms)  INSERT INTO `skill_sets` (`applicant_id`, `created_at`, `skill_id`, `updated_at`)   
VALUES (294, '2014-04-09 15:20:12', 15, '2014-04-09 15:20:12')
(0.6ms)  COMMIT
Job Load (0.2ms)  SELECT `jobs`.* FROM `jobs` WHERE `jobs`.`id` = 1 LIMIT 1
(0.1ms)  BEGIN
SQL (0.2ms)  INSERT INTO `job_applications` (`applicant_id`, `job_id`) VALUES (294, 1)
(0.5ms)  COMMIT
Redirected to http://localhost:3000/jobs/1
Completed 302 Found in 29ms (ActiveRecord: 19.2ms)
Was it helpful?

Solution

As per the server log, there is a warning Unpermitted parameters: resumes_attributes, job_id.

What you need to do here is, permit resumes_attributes and job_id in ApplicantsController.

For example:

  def applicant_params
    params.require(:applicant).permit(:fname, :lname, :phone,..., resumes_attributes: [:name, :attachment,...])
  end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top