質問編集履歴

6

不要な記述を削除

2016/09/18 04:34

投稿

rendezvous_pc
rendezvous_pc

スコア12

test CHANGED
File without changes
test CHANGED
@@ -146,7 +146,7 @@
146
146
 
147
147
  = j.name
148
148
 
149
- -# = uj.number_field :position_id, class: "form-control"
149
+ ontrol"
150
150
 
151
151
  = f.submit "送信する", class: "btn btn-success"```
152
152
 

5

ソースの変更

2016/09/18 04:34

投稿

rendezvous_pc
rendezvous_pc

スコア12

test CHANGED
File without changes
test CHANGED
@@ -128,7 +128,7 @@
128
128
 
129
129
  .form-group
130
130
 
131
- = f.label :name, "ユーザーID: @cyllabus_jp", class: "control-label"
131
+ = f.label :name, "ユーザーID: tanaka tarou", class: "control-label"
132
132
 
133
133
  = f.text_field :name, class: "form-control"
134
134
 

4

補足の追記

2016/09/15 14:05

投稿

rendezvous_pc
rendezvous_pc

スコア12

test CHANGED
File without changes
test CHANGED
@@ -159,3 +159,13 @@
159
159
  ・ストロングパラメーターの設定方法
160
160
 
161
161
  ・ビューのfield_for部分の書き方
162
+
163
+
164
+
165
+ ■補足
166
+
167
+ Web上のソースを色々と参考にさせていただいた結果、
168
+
169
+ 収集のつかない状態となっております。
170
+
171
+ お見苦しいソースコードとなってしまい、大変申し訳ございません。

3

ソースに対する補足を追記

2016/09/15 14:03

投稿

rendezvous_pc
rendezvous_pc

スコア12

test CHANGED
File without changes
test CHANGED
@@ -44,6 +44,10 @@
44
44
 
45
45
  ■ソース
46
46
 
47
+
48
+
49
+ モデル
50
+
47
51
  ```Ruby
48
52
 
49
53
  class User < ActiveRecord::Base
@@ -80,6 +84,8 @@
80
84
 
81
85
 
82
86
 
87
+ コントローラー
88
+
83
89
  ```Ruby
84
90
 
85
91
  class UsersController < ApplicationController
@@ -107,6 +113,8 @@
107
113
  ```
108
114
 
109
115
 
116
+
117
+ ビュー
110
118
 
111
119
  ```haml
112
120
 
@@ -141,3 +149,13 @@
141
149
  -# = uj.number_field :position_id, class: "form-control"
142
150
 
143
151
  = f.submit "送信する", class: "btn btn-success"```
152
+
153
+
154
+
155
+ ■不明点
156
+
157
+
158
+
159
+ ・ストロングパラメーターの設定方法
160
+
161
+ ・ビューのfield_for部分の書き方

2

ソースコードの貼り付け

2016/09/15 14:02

投稿

rendezvous_pc
rendezvous_pc

スコア12

test CHANGED
File without changes
test CHANGED
@@ -39,3 +39,105 @@
39
39
  ■参考にした記事
40
40
 
41
41
  https://teratail.com/questions/19499
42
+
43
+
44
+
45
+ ■ソース
46
+
47
+ ```Ruby
48
+
49
+ class User < ActiveRecord::Base
50
+
51
+ authenticates_with_sorcery!
52
+
53
+
54
+
55
+ has_many :user_jobs
56
+
57
+ has_many :jobs, :through => :user_jobs
58
+
59
+ accepts_nested_attributes_for :user_jobs, allow_destroy: true
60
+
61
+ end
62
+
63
+
64
+
65
+ ```
66
+
67
+
68
+
69
+ ```Ruby
70
+
71
+ class UserJob < ActiveRecord::Base
72
+
73
+ belongs_to :user
74
+
75
+ belongs_to :job
76
+
77
+ end
78
+
79
+ ```
80
+
81
+
82
+
83
+ ```Ruby
84
+
85
+ class UsersController < ApplicationController
86
+
87
+ def edit
88
+
89
+ @user = current_user
90
+
91
+ @user.user_jobs.build
92
+
93
+ @job = Job.all
94
+
95
+ end
96
+
97
+
98
+
99
+ def params_user
100
+
101
+ params.require(:user).permit(:name)
102
+
103
+ end
104
+
105
+ end
106
+
107
+ ```
108
+
109
+
110
+
111
+ ```haml
112
+
113
+ = form_for @user, url: settings_path, method: :put do |f|
114
+
115
+ %h2
116
+
117
+ 設定
118
+
119
+ .form-body
120
+
121
+ .form-group
122
+
123
+ = f.label :name, "ユーザーID: @cyllabus_jp", class: "control-label"
124
+
125
+ = f.text_field :name, class: "form-control"
126
+
127
+ .form-group
128
+
129
+ = f.fields_for :user_jobs do |uj|
130
+
131
+ = uj.label :user_jobs, "職種", class: "control-label"
132
+
133
+ %p
134
+
135
+ -@job.each do |j|
136
+
137
+ = uj.check_box :job_ids, { multiple: true, checked: @user.user_jobs.include?(j.id), include_hidden: false }, j.id
138
+
139
+ = j.name
140
+
141
+ -# = uj.number_field :position_id, class: "form-control"
142
+
143
+ = f.submit "送信する", class: "btn btn-success"```

1

備考項目の追加

2016/09/15 13:58

投稿

rendezvous_pc
rendezvous_pc

スコア12

test CHANGED
File without changes
test CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
  ■対象テーブル
8
8
 
9
- users
9
+ users(id, name)
10
10
 
11
- jobs
11
+ jobs(id, name)
12
12
 
13
- user_jobs
13
+ user_jobs(id, user_id, job_id)
14
14
 
15
15
 
16
16
 
@@ -26,6 +26,16 @@
26
26
 
27
27
 
28
28
 
29
+ ■備考
30
+
31
+ user情報を編集する画面では、
32
+
33
+ 氏名(users.name)の更新と、
34
+
35
+ 職種(user_jobs)レコードの新規作成、削除を目的としています
36
+
37
+
38
+
29
39
  ■参考にした記事
30
40
 
31
41
  https://teratail.com/questions/19499