質問編集履歴

3

code blocked

2021/07/21 15:58

投稿

yoshidesu
yoshidesu

スコア4

test CHANGED
File without changes
test CHANGED
@@ -268,7 +268,7 @@
268
268
 
269
269
  end
270
270
 
271
- ~~~
271
+ ```
272
272
 
273
273
 
274
274
 

2

gemfile, application_controllerを追加しました

2021/07/21 15:57

投稿

yoshidesu
yoshidesu

スコア4

test CHANGED
File without changes
test CHANGED
@@ -92,6 +92,188 @@
92
92
 
93
93
 
94
94
 
95
+ OS 環境は mac os 10.15.6 です。
96
+
97
+
98
+
99
+ gemfile は以下です。
100
+
101
+
102
+
103
+ ```
104
+
105
+ source 'https://rubygems.org'
106
+
107
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
108
+
109
+
110
+
111
+ ruby '3.0.1'
112
+
113
+
114
+
115
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
116
+
117
+ gem 'rails', '~> 6.1.4'
118
+
119
+ # Use sqlite3 as the database for Active Record
120
+
121
+ gem 'sqlite3', '~> 1.4'
122
+
123
+ # Use Puma as the app server
124
+
125
+ gem 'puma', '~> 5.0'
126
+
127
+ # Use SCSS for stylesheets
128
+
129
+ gem 'sass-rails', '>= 6'
130
+
131
+ # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
132
+
133
+ gem 'webpacker', '~> 5.0'
134
+
135
+ # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
136
+
137
+ gem 'turbolinks', '~> 5'
138
+
139
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
140
+
141
+ gem 'jbuilder', '~> 2.7'
142
+
143
+ # Use Redis adapter to run Action Cable in production
144
+
145
+ # gem 'redis', '~> 4.0'
146
+
147
+ # Use Active Model has_secure_password
148
+
149
+ gem 'bcrypt'
150
+
151
+
152
+
153
+ # Use Active Storage variant
154
+
155
+ # gem 'image_processing', '~> 1.2'
156
+
157
+
158
+
159
+ # Reduces boot times through caching; required in config/boot.rb
160
+
161
+ gem 'bootsnap', '>= 1.4.4', require: false
162
+
163
+
164
+
165
+ group :development, :test do
166
+
167
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
168
+
169
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
170
+
171
+ end
172
+
173
+
174
+
175
+ group :development do
176
+
177
+ # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
178
+
179
+ gem 'web-console', '>= 4.1.0'
180
+
181
+ # Display performance information such as SQL time and flame graphs for each request in your browser.
182
+
183
+ # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
184
+
185
+ gem 'rack-mini-profiler', '~> 2.0'
186
+
187
+ gem 'listen', '~> 3.3'
188
+
189
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
190
+
191
+ gem 'spring'
192
+
193
+ end
194
+
195
+
196
+
197
+ group :test do
198
+
199
+ # Adds support for Capybara system testing and selenium driver
200
+
201
+ gem 'capybara', '>= 3.26'
202
+
203
+ gem 'selenium-webdriver'
204
+
205
+ # Easy installation and use of web drivers to run system tests with browsers
206
+
207
+ gem 'webdrivers'
208
+
209
+ end
210
+
211
+
212
+
213
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
214
+
215
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
216
+
217
+ ```
218
+
219
+
220
+
221
+ application_controllerのコードは以下です。
222
+
223
+
224
+
225
+ ```
226
+
227
+ class ApplicationController < ActionController::Base
228
+
229
+ before_action :set_current_user
230
+
231
+
232
+
233
+ def set_current_user
234
+
235
+ @current_user = User.find_by(id: session[:user_id])
236
+
237
+ end
238
+
239
+
240
+
241
+ def authenticate_user
242
+
243
+ if @current_user == nil
244
+
245
+ flash[:notice]= "ログインが必要です"
246
+
247
+ redirect_to("/login")
248
+
249
+ end
250
+
251
+ end
252
+
253
+
254
+
255
+ def forbid_login_user
256
+
257
+ if @current_user
258
+
259
+ flash[:notice]= "すでにログインしています"
260
+
261
+ redirect_to("/posts/index")
262
+
263
+ end
264
+
265
+ end
266
+
267
+
268
+
269
+ end
270
+
271
+ ~~~
272
+
273
+
274
+
275
+ 作成中のものは、Twitterのような簡単な投稿サイトデモです。
276
+
95
277
 
96
278
 
97
279
  宜しくお願いします。

1

code blocked

2021/07/21 15:57

投稿

yoshidesu
yoshidesu

スコア4

test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
 
44
44
 
45
-
45
+ ```
46
46
 
47
47
  class ApplicationController < ActionController::Base
48
48
 
@@ -88,6 +88,8 @@
88
88
 
89
89
  end
90
90
 
91
+ ```
92
+
91
93
 
92
94
 
93
95