teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

別手法の結果を追記

2018/12/09 13:46

投稿

hiro_87g
hiro_87g

スコア28

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- 仕事情報を投稿する機能を作成しています。
1
+ 自分の職歴を投稿する機能を作成しています。
2
2
 
3
3
  job_category(職種)、annual_salary(年収)、position(役職)はデータベースに反映されるのですが、
4
4
  start_date(仕事開始日) と end_date(仕事終了日) がデータベースに反映されずに躓いております。
@@ -23,6 +23,10 @@
23
23
 
24
24
  controllers/careers_controller.rb
25
25
  ```ここに言語を入力
26
+ def new
27
+ @career = Career.new
28
+ end
29
+
26
30
  def create
27
31
  Career.create(
28
32
  job_category: career_params[:job_category],
@@ -62,4 +66,42 @@
62
66
 
63
67
  "start_date(1i)"=>"1989", "start_date(2i)"=>"1", "start_date(3i)"=>"4", "end_date(1i)"=>"1990", "end_date(2i)"=>"2", "end_date(3i)"=>"3"
64
68
 
65
- という(1i)〜(3i)がうまく情報渡せていないように見えます。
69
+ という(1i)〜(3i)がうまく情報渡せていないように見えます。
70
+
71
+
72
+
73
+ ---
74
+ 追記です。
75
+ controllerのcreateにて career_params を読み込むように変えてみましたが、
76
+ 今度は ROLLBACK が起きて全て登録できなくなってしまいました…。
77
+
78
+ controllers/careers_controller.rb
79
+ ```ここに言語を入力
80
+ def new
81
+ @career = Career.new
82
+ end
83
+
84
+ def create
85
+ @career = Career.create(career_params)
86
+
87
+ logger.debug @career.errors.inspect
88
+ end
89
+ ```
90
+
91
+ エラー:
92
+
93
+ ```ここに言語を入力
94
+ Started POST "/careers" for 127.0.0.1 at 2018-12-09 22:40:58 +0900
95
+ Processing by CareersController#create as HTML
96
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"Q3E41N8ZMgNky4zx6TH/thUk2rVqQMmJpDprCBhbuUi+AjQINyLj6rz9h1hZxjzejUyrQ4xBtRBYbmOIOqLMkg==", "career"=>{"job_category"=>"111", "annual_salary"=>"2222", "position"=>"3333", "start_date(1i)"=>"1989", "start_date(2i)"=>"1", "start_date(3i)"=>"1", "end_date(1i)"=>"1989", "end_date(2i)"=>"1", "end_date(3i)"=>"1"}, "commit"=>"送信"}
97
+ User Load (1.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 9 ORDER BY `users`.`id` ASC LIMIT 1
98
+ ↳ app/controllers/careers_controller.rb:86
99
+ (0.3ms) BEGIN
100
+ ↳ app/controllers/careers_controller.rb:36
101
+ (2.0ms) ROLLBACK
102
+ ↳ app/controllers/careers_controller.rb:36
103
+ #<ActiveModel::Errors:0x00007fd55dc2fc88 @base=#<Career id: nil, job_category: "111", created_at: nil, updated_at: nil, user_id: nil, annual_salary: 2222, position: "3333", start_date: "1989-01-01", end_date: "1989-01-01">, @messages={:user=>["を入力してください"]}, @details={:user=>[{:error=>:blank}]}>
104
+ Rendering careers/create.html.erb within layouts/application
105
+ Rendered careers/create.html.erb within layouts/application (0.5ms)
106
+ Completed 200 OK in 278ms (Views: 225.5ms | ActiveRecord: 3.4ms)
107
+ ```

2

エラーの追記

2018/12/09 13:46

投稿

hiro_87g
hiro_87g

スコア28

title CHANGED
File without changes
body CHANGED
@@ -37,4 +37,29 @@
37
37
  def career_params
38
38
  params.require(:career).permit(:job_category, :annual_salary, :position, :start_date, :end_date)
39
39
  end
40
- ```
40
+ ```
41
+
42
+ エラー
43
+ ```ここに言語を入力
44
+ Started POST "/careers" for 127.0.0.1 at 2018-12-09 14:07:37 +0900
45
+ Processing by CareersController#create as HTML
46
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"XXXXXXXXXXXXX/X/XXXXXX==", "career"=>{"job_category"=>"100", "annual_salary"=>"200", "position"=>"300", "start_date(1i)"=>"1989", "start_date(2i)"=>"1", "start_date(3i)"=>"4", "end_date(1i)"=>"1990", "end_date(2i)"=>"2", "end_date(3i)"=>"3"}, "commit"=>"送信"}
47
+ User Load (0.8ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 9 ORDER BY `users`.`id` ASC LIMIT 1
48
+ ↳ app/controllers/careers_controller.rb:72
49
+ (0.4ms) BEGIN
50
+ ↳ app/controllers/careers_controller.rb:17
51
+ User Load (0.7ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 9 LIMIT 1
52
+ ↳ app/controllers/careers_controller.rb:17
53
+ Career Create (4.5ms) INSERT INTO `careers` (`job_category`, `created_at`, `updated_at`, `user_id`, `annual_salary`, `position`) VALUES ('100', '2018-12-09 14:07:37', '2018-12-09 14:07:37', 9, 200, '300')
54
+ ↳ app/controllers/careers_controller.rb:17
55
+ (81.8ms) COMMIT
56
+ ↳ app/controllers/careers_controller.rb:17
57
+ #<ActiveModel::Errors:0x00007f8901294e38 @base=#<Career id: 64, job_category: "100", created_at: "2018-12-09 05:07:37", updated_at: "2018-12-09 05:07:37", user_id: 9, annual_salary: 200, position: "300", start_date: nil, end_date: nil>, @messages={}, @details={}>
58
+ Rendering careers/create.html.erb within layouts/application
59
+ Rendered careers/create.html.erb within layouts/application (0.7ms)
60
+ Completed 200 OK in 722ms (Views: 613.2ms | ActiveRecord: 88.1ms)
61
+ ```
62
+
63
+ "start_date(1i)"=>"1989", "start_date(2i)"=>"1", "start_date(3i)"=>"4", "end_date(1i)"=>"1990", "end_date(2i)"=>"2", "end_date(3i)"=>"3"
64
+
65
+ という(1i)〜(3i)がうまく情報渡せていないように見えます。

1

タグの追加

2018/12/09 05:13

投稿

hiro_87g
hiro_87g

スコア28

title CHANGED
File without changes
body CHANGED
File without changes