質問編集履歴

1

情報の追記

2018/07/17 02:24

投稿

kozica
kozica

スコア58

test CHANGED
File without changes
test CHANGED
@@ -62,10 +62,128 @@
62
62
 
63
63
  #personal_logs_controller.rb
64
64
 
65
+ class PersonalLogsController < ApplicationController
66
+
67
+ before_action :set_personal_log, only: [:show, :edit, :update, :destroy]
68
+
69
+
70
+
65
- def index
71
+ def index
66
72
 
67
73
  @personal_logs = PersonalLog.all
68
74
 
75
+ end
76
+
77
+
78
+
79
+ def show
80
+
81
+ end
82
+
83
+
84
+
85
+ def new
86
+
87
+ @personal_log = PersonalLog.new
88
+
89
+ end
90
+
91
+
92
+
93
+ def edit
94
+
95
+ end
96
+
97
+
98
+
99
+ def create
100
+
101
+ @personal_log = PersonalLog.new(personal_log_params)
102
+
103
+
104
+
105
+ respond_to do |format|
106
+
107
+ if @personal_log.save
108
+
109
+ format.html { redirect_to @personal_log, notice: 'Personal log was successfully created.' }
110
+
111
+ format.json { render :show, status: :created, location: @personal_log }
112
+
113
+ else
114
+
115
+ format.html { render :new }
116
+
117
+ format.json { render json: @personal_log.errors, status: :unprocessable_entity }
118
+
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+
125
+
126
+
127
+ def update
128
+
129
+ respond_to do |format|
130
+
131
+ if @personal_log.update(personal_log_params)
132
+
133
+ format.html { redirect_to @personal_log, notice: 'Personal log was successfully updated.' }
134
+
135
+ format.json { render :show, status: :ok, location: @personal_log }
136
+
137
+ else
138
+
139
+ format.html { render :edit }
140
+
141
+ format.json { render json: @personal_log.errors, status: :unprocessable_entity }
142
+
143
+ end
144
+
145
+ end
146
+
147
+ end
148
+
149
+
150
+
151
+ def destroy
152
+
153
+ @personal_log.destroy
154
+
155
+ respond_to do |format|
156
+
157
+ format.html { redirect_to personal_logs_url, notice: 'Personal log was successfully destroyed.' }
158
+
159
+ format.json { head :no_content }
160
+
161
+ end
162
+
163
+ end
164
+
165
+
166
+
167
+ private
168
+
169
+ # Use callbacks to share common setup or constraints between actions.
170
+
171
+ def set_personal_log
172
+
173
+ @personal_log = PersonalLog.find(params[:id])
174
+
175
+ end
176
+
177
+
178
+
179
+ # Never trust parameters from the scary internet, only allow the white list through.
180
+
181
+ def personal_log_params
182
+
183
+ params.fetch(:personal_log, {})
184
+
185
+ end
186
+
69
187
  end
70
188
 
71
189
  ```
@@ -74,16 +192,66 @@
74
192
 
75
193
  #index.html.erb
76
194
 
195
+ <p id="notice"><%= notice %></p>
196
+
197
+
198
+
199
+ <h1>Personal Logs</h1>
200
+
201
+
202
+
203
+ <table border = "5">
204
+
205
+
206
+
207
+ <thead>
208
+
209
+ <tr>
210
+
211
+ <th>data</th>
212
+
213
+ </tr>
214
+
215
+ </thead>
216
+
77
- <% @personal_logs.each do |personal_log| %>
217
+ <% @personal_logs.each do |personal_log| %>
218
+
219
+ <tbody>
78
220
 
79
221
  <tr>
80
222
 
81
- <td><%= personal_log.data %></td>
223
+ <td><%= personal_log.decrypted_data %></td>
82
224
 
83
225
  </tr>
84
226
 
227
+ </tbody>
228
+
85
229
  <% end %>
86
230
 
231
+ </table>
232
+
233
+ ```
234
+
235
+ ```ruby
236
+
237
+ #model/personal_log.rb
238
+
239
+ require 'openssl'
240
+
241
+ require 'base64'
242
+
243
+
244
+
245
+ class PersonalLog < ApplicationRecord
246
+
247
+ def decrypted_data
248
+
249
+ return self.id
250
+
251
+ end
252
+
253
+ end
254
+
87
255
  ```
88
256
 
89
257