質問編集履歴
4
誤字
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
[Ruby&HTML5&CSS3]Webサイトが正しく表示されない
|
test
CHANGED
File without changes
|
3
誤字
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[Ruby&HTML5&CSS3]Webサイトが正しく表示されない
|
1
|
+
ご[Ruby&HTML5&CSS3]Webサイトが正しく表示されない
|
test
CHANGED
@@ -248,7 +248,7 @@
|
|
248
248
|
|
249
249
|
```
|
250
250
|
|
251
|
-
###img_upl
|
251
|
+
###img_upload.rb
|
252
252
|
|
253
253
|
```Ruby
|
254
254
|
|
2
一部追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,279 @@
|
|
1
1
|
###RubyとHTML,CSSで掲示板のようなWebサービスを作っています。Safariでは正しく表示されるのですが、Chromeでは正しく表示されません。どうしたらいいでしょうか。
|
2
2
|
|
3
|
+
###app.rb
|
4
|
+
|
5
|
+
```Ruby
|
6
|
+
|
7
|
+
require 'bundler/setup'
|
8
|
+
|
9
|
+
Bundler.require
|
10
|
+
|
11
|
+
require 'sinatra/reloader' if development?
|
12
|
+
|
13
|
+
require 'sinatra/activerecord'
|
14
|
+
|
15
|
+
require './models'
|
16
|
+
|
17
|
+
require 'net/http'
|
18
|
+
|
19
|
+
require "rest-client"
|
20
|
+
|
21
|
+
require "date"
|
22
|
+
|
23
|
+
require "./image_uploader.rb"
|
24
|
+
|
25
|
+
enable :sessions
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
helpers do
|
30
|
+
|
31
|
+
def current_user
|
32
|
+
|
33
|
+
User.find_by(id: session[:user])
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
get '/' do
|
42
|
+
|
43
|
+
if current_user.nil?
|
44
|
+
|
45
|
+
@contributions = Contribution.none
|
46
|
+
|
47
|
+
erb :choice
|
48
|
+
|
49
|
+
else
|
50
|
+
|
51
|
+
@contributions = Contribution.all
|
52
|
+
|
53
|
+
erb :profile
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
get '/signup' do
|
62
|
+
|
63
|
+
erb :sign_up
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
get '/timelines' do
|
70
|
+
|
71
|
+
if current_user.nil?
|
72
|
+
|
73
|
+
@contributions = Contribution.none
|
74
|
+
|
75
|
+
else
|
76
|
+
|
77
|
+
@contributions = Contribution.all.order("created_at desc")
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
erb :time_line
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
post '/timelines/new' do
|
86
|
+
|
87
|
+
#current_user.contributions.create(text: params[:text])
|
88
|
+
|
89
|
+
current_user.contributions.create({
|
90
|
+
|
91
|
+
title: params[:title],
|
92
|
+
|
93
|
+
text: params[:text],
|
94
|
+
|
95
|
+
time: "#{Date.today.year}年#{Date.today.month}月#{Date.today.day}日#{DateTime.now.hour}時#{DateTime.now.minute}分#{DateTime.now.second}秒",
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
})
|
100
|
+
|
101
|
+
redirect '/timelines'
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
post '/timelines/:id/delete' do
|
108
|
+
|
109
|
+
del = Contribution.find(params[:id])
|
110
|
+
|
111
|
+
del.destroy
|
112
|
+
|
113
|
+
redirect '/timelines'
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
post '/signup' do
|
120
|
+
|
121
|
+
user = User.create(
|
122
|
+
|
123
|
+
name: params[:name],
|
124
|
+
|
125
|
+
mail: params[:mail],
|
126
|
+
|
127
|
+
password: params[:password],
|
128
|
+
|
129
|
+
profile_image: "",
|
130
|
+
|
131
|
+
password_confirmation: params[:password_confirmation]
|
132
|
+
|
133
|
+
)
|
134
|
+
|
135
|
+
if user.persisted?
|
136
|
+
|
137
|
+
session[:user] = user.id
|
138
|
+
|
139
|
+
image_upload(params[:image])
|
140
|
+
|
141
|
+
redirect '/'
|
142
|
+
|
143
|
+
else
|
144
|
+
|
145
|
+
redirect '/signup'
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
post '/timelines/like/:id' do
|
154
|
+
|
155
|
+
current_user.likes.create({
|
156
|
+
|
157
|
+
contribution_id: Contribution.find_by(id: params[:id]).id,
|
158
|
+
|
159
|
+
})
|
160
|
+
|
161
|
+
redirect '/timelines'
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
get '/signout' do
|
168
|
+
|
169
|
+
session[:user] = nil
|
170
|
+
|
171
|
+
redirect '/'
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
get '/signin' do
|
178
|
+
|
179
|
+
erb :sign_in
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
post '/signin' do
|
186
|
+
|
187
|
+
user = User.find_by(mail: params[:mail])
|
188
|
+
|
189
|
+
if user && user.authenticate(params[:password])
|
190
|
+
|
191
|
+
session[:user] = user.id
|
192
|
+
|
193
|
+
redirect '/'
|
194
|
+
|
195
|
+
else
|
196
|
+
|
197
|
+
redirect '/signin'
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
get '/contribution/:id' do
|
206
|
+
|
207
|
+
@contribution = Contribution.find_by(id: params[:id])
|
208
|
+
|
209
|
+
@comments = Contribution.find_by(id: params[:id]).comments.all
|
210
|
+
|
211
|
+
erb :comment
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
post '/timelines/comment/new/:id' do
|
218
|
+
|
219
|
+
contributions = Contribution.find_by(id: params[:id])
|
220
|
+
|
221
|
+
contributions.comments.create({
|
222
|
+
|
223
|
+
comment: params[:comment],
|
224
|
+
|
225
|
+
time: "#{Date.today.year}年#{Date.today.month}月#{Date.today.day}日#{DateTime.now.hour}時#{DateTime.now.minute}分#{DateTime.now.second}秒",
|
226
|
+
|
227
|
+
user_id: current_user.id
|
228
|
+
|
229
|
+
})
|
230
|
+
|
231
|
+
redirect "/contribution/#{params[:id]}"
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
post '/timelines/comment/:id' do
|
238
|
+
|
239
|
+
current_user.likes.create({
|
240
|
+
|
241
|
+
contribution_id: Contribution.find_by(id: params[:id]).id,
|
242
|
+
|
243
|
+
})
|
244
|
+
|
245
|
+
redirect "/contribution/#{params[:id]}"
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
###img_uplpad.rb
|
252
|
+
|
253
|
+
```Ruby
|
254
|
+
|
255
|
+
def image_upload(img)
|
256
|
+
|
257
|
+
logger.info "upload now"
|
258
|
+
|
259
|
+
tempfile = img[:tempfile]
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
upload = Cloudinary::Uploader.upload(tempfile.path)
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
contents = User.last
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
contents.update_attribute(:profile_image, upload['url'])
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
```
|
276
|
+
|
3
277
|
###time_line.erb
|
4
278
|
|
5
279
|
```HTML
|
1
一部コードが間違っていました。
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|