質問編集履歴
1
新規にコードを追記。
test
CHANGED
File without changes
|
test
CHANGED
@@ -115,3 +115,281 @@
|
|
115
115
|
それともjavaScriptなのか、このような現象はどこのファイルが原因なのでしょうか?教えてください。
|
116
116
|
|
117
117
|
宜しくお願いします。
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
追記:
|
122
|
+
|
123
|
+
countアクションを追加
|
124
|
+
|
125
|
+
```ここに言語を入力
|
126
|
+
|
127
|
+
app/controllers/staff/messages_controller.rb
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
class Staff::MessagesController < Staff::Base
|
132
|
+
|
133
|
+
before_action :reject_non_xhr, only: [ :count ]
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
def index
|
138
|
+
|
139
|
+
@messages = Message.where(deleted: false).page(params[:page])
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
# GET
|
146
|
+
|
147
|
+
def inbound
|
148
|
+
|
149
|
+
@messages = CustomerMessage.where(deleted: false).page(params[:page])
|
150
|
+
|
151
|
+
render action: 'index'
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
# GET
|
158
|
+
|
159
|
+
def outbound
|
160
|
+
|
161
|
+
@messages = StaffMessage.where(deleted: false).page(params[:page])
|
162
|
+
|
163
|
+
render action: 'index'
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
# GET
|
170
|
+
|
171
|
+
def deleted
|
172
|
+
|
173
|
+
@messages = Message.where(deleted: true).page(params[:page])
|
174
|
+
|
175
|
+
render action: 'index'
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
#GET
|
182
|
+
|
183
|
+
def count
|
184
|
+
|
185
|
+
render text: CustomerMessage.unprocessed.count
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
def show
|
192
|
+
|
193
|
+
@message = Message.find(params[:id])
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
def destroy
|
200
|
+
|
201
|
+
message = CustomerMessage.find(params[:id])
|
202
|
+
|
203
|
+
message.update_column(:deleted, true)
|
204
|
+
|
205
|
+
flash.notice = '問い合わせを削除しました。'
|
206
|
+
|
207
|
+
redirect_back(fallback_location: root_path)
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
# POST/DELETE
|
214
|
+
|
215
|
+
def tag
|
216
|
+
|
217
|
+
message = CustomerMessage.find(params[:id])
|
218
|
+
|
219
|
+
if request.post?
|
220
|
+
|
221
|
+
message.add_tag(params[:label])
|
222
|
+
|
223
|
+
elsif request.delete?
|
224
|
+
|
225
|
+
message.remove_tag(params[:label])
|
226
|
+
|
227
|
+
else
|
228
|
+
|
229
|
+
raise
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
render text: 'OK'
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
```
|
242
|
+
|
243
|
+
CutomerMessageモデルにunprocessedスコープを定義する。
|
244
|
+
|
245
|
+
```ここに言語を入力
|
246
|
+
|
247
|
+
app/models/customer_message.rb
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
class CustomerMessage < Message
|
252
|
+
|
253
|
+
scope :unprocessed, -> { where(status: 'new', deleted: false) }
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
ヘッダ部分に「新規問い合わせ」リンクを表示するためのヘルパーメソッドnumber_of_unprocesser_messagesを定義。
|
260
|
+
|
261
|
+
```ここに言語を入力
|
262
|
+
|
263
|
+
app/helpers/staff_helper.rb
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
module StaffHelper
|
268
|
+
|
269
|
+
include HtmlBuilder
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
def number_of_unprocessed_messages
|
274
|
+
|
275
|
+
markup do |m|
|
276
|
+
|
277
|
+
m.a(href: inbound_staff_messages_path) do
|
278
|
+
|
279
|
+
m << '新規問い合わせ'
|
280
|
+
|
281
|
+
if (c = CustomerMessage.unprocessed.count) > 0
|
282
|
+
|
283
|
+
anchor_text = "(#{c})"
|
284
|
+
|
285
|
+
else
|
286
|
+
|
287
|
+
anchor_text = ''
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
m.span(anchor_text, id: 'number-of-unprocessed-messages')
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
```
|
304
|
+
|
305
|
+
ヘッダにリンクを設置。
|
306
|
+
|
307
|
+
```ここに言語を入力
|
308
|
+
|
309
|
+
app/view/staff/shared/_header.html.erb
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
<header>
|
314
|
+
|
315
|
+
<%= link_to 'CHIBI', :staff_root, class: 'logo-mark' %>
|
316
|
+
|
317
|
+
<%= content_tag(:span, flash.notice, class: 'notice') if flash.notice %>
|
318
|
+
|
319
|
+
<%= content_tag(:span, flash.alert, class: 'alert') if flash.alert %>
|
320
|
+
|
321
|
+
<%=
|
322
|
+
|
323
|
+
if current_staff_member
|
324
|
+
|
325
|
+
link_to 'ログアウト', :staff_session, method: :delete
|
326
|
+
|
327
|
+
else
|
328
|
+
|
329
|
+
link_to 'ログイン', :staff_login
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
%>
|
334
|
+
|
335
|
+
<%= link_to 'アカウント', :staff_account if current_staff_member %>
|
336
|
+
|
337
|
+
<%= number_of_unprocessed_messages if current_staff_member %>
|
338
|
+
|
339
|
+
</header>
|
340
|
+
|
341
|
+
```
|
342
|
+
|
343
|
+
ルーティングで定義されるヘルパーメソッドをapp/assetsディレクトリにあるファイルの中で使えるようにする。
|
344
|
+
|
345
|
+
```ここに言語を入力
|
346
|
+
|
347
|
+
config/initializers/assets.rb
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
Rails.application.config.assets.precompile +=
|
352
|
+
|
353
|
+
%w( staff.css admin.css customer.css staff.js admin.js customer.js )
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
Sprockets::Context.send(:include, Rails.application.routes.url_helpers)
|
358
|
+
|
359
|
+
```
|
360
|
+
|
361
|
+
CoffeeScriptに対して擬似的なグローバル変数を提供する。
|
362
|
+
|
363
|
+
```ここに言語を入力
|
364
|
+
|
365
|
+
app/assets/javascripts/staff/paths.js.coffee.erb
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
window.named_paths = []
|
370
|
+
|
371
|
+
<% %w(count_staff_messages tag_staff_message).each do |name| %>
|
372
|
+
|
373
|
+
<% route = Rails.application.routes.named_routes[name] %>
|
374
|
+
|
375
|
+
<%= "window.named_paths['#{name}'] = '#{route.path.spec.left.to_s}'\n" %>
|
376
|
+
|
377
|
+
<% end %>
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
window.path_for = (name, ids = {}) ->
|
382
|
+
|
383
|
+
path = window.named_paths[name]
|
384
|
+
|
385
|
+
for key, id of ids
|
386
|
+
|
387
|
+
path = path.replace(new RegExp(":#{key}\\b"), id)
|
388
|
+
|
389
|
+
path
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
```
|
394
|
+
|
395
|
+
関連すると思われるコードを追記しました。
|