teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

コードの記述を修正しました

2016/09/28 23:56

投稿

kenny_sayama
kenny_sayama

スコア1036

title CHANGED
File without changes
body CHANGED
@@ -7,17 +7,17 @@
7
7
 
8
8
  # 今月の月初めと月末までの投稿数を取得
9
9
  this_month = Time.now.at_beginning_of_month
10
- to_this_month = this_month + 1.month - 1.day
10
+ to_this_month = this_month + 1.month
11
11
  @this_month = Post.where(user_id: @user.id, created_at: this_month...to_this_month).count
12
12
 
13
13
  # 先月の投稿数
14
14
  last_month = this_month.last_month
15
- to_last_month = last_month + 1.month - 1.day
15
+ to_last_month = last_month + 1.month
16
16
  @last_month = Post.where(user_id: @user.id, created_at: last_month...to_last_month).count
17
17
 
18
18
  # 先々月の投稿数
19
19
  month_before_last = this_month.month_ago(2)
20
- to_month_before_last = month_before_last + 1.month - 1.day
20
+ to_month_before_last = month_before_last + 1.month
21
21
  @last_month = Post.where(user_id: @user.id, created_at: last_month...to_last_month).count
22
22
  ```
23
23
 

1

文字の修正

2016/09/28 23:56

投稿

kenny_sayama
kenny_sayama

スコア1036

title CHANGED
File without changes
body CHANGED
@@ -8,17 +8,17 @@
8
8
  # 今月の月初めと月末までの投稿数を取得
9
9
  this_month = Time.now.at_beginning_of_month
10
10
  to_this_month = this_month + 1.month - 1.day
11
- @this_month = Post.where(user_id: @user.id, status: 'answered', created_at: this_month...to_this_month).count
11
+ @this_month = Post.where(user_id: @user.id, created_at: this_month...to_this_month).count
12
12
 
13
13
  # 先月の投稿数
14
14
  last_month = this_month.last_month
15
15
  to_last_month = last_month + 1.month - 1.day
16
- @last_month = Post.where(user_id: @user.id, status: 'answered', created_at: last_month...to_last_month).count
16
+ @last_month = Post.where(user_id: @user.id, created_at: last_month...to_last_month).count
17
17
 
18
18
  # 先々月の投稿数
19
19
  month_before_last = this_month.month_ago(2)
20
20
  to_month_before_last = month_before_last + 1.month - 1.day
21
- @last_month = Post.where(user_id: @user.id, status: 'answered', created_at: last_month...to_last_month).count
21
+ @last_month = Post.where(user_id: @user.id, created_at: last_month...to_last_month).count
22
22
  ```
23
23
 
24
24
  もっとすっきりかけると思うのですが、いい案が思いつかず、お力を貸していただきたいです