質問編集履歴

3

初心者マークの追加

2023/01/09 10:00

投稿

tyottomatetya1
tyottomatetya1

スコア0

test CHANGED
File without changes
test CHANGED
@@ -116,7 +116,7 @@
116
116
 
117
117
  ### 参考にした資料
118
118
 
119
- 「【Ruby on Rails】railsでスタディープラスっぽいもの作ろうとしてみた(グラフ表示)」
119
+ 「【Ruby on Rails】railsでスタディープラスっぽいもの作ろうとしてみた(グラフ表示) 
120
120
  https://qiita.com/Yu_unI1/items/c3c977288054560fe0e6
121
121
 
122
122
  「Chartkickを使って、グラフを作成してみた」

2

問題点の更新

2023/01/09 09:28

投稿

tyottomatetya1
tyottomatetya1

スコア0

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Railsでスマホアプリの利用時間をアプリジャンルごとにグラフ化させるアプリを開発しています。
4
4
  現在は、入力した値(使用アプリ名や利用時間など)をChartkickという機能を用いてグラフ化させようとしている段階です。
5
- 保存する際に以下のエラーメッセージが発生しました。
5
+ グラフが表示されるページに戻るボタン押した際に以下のエラーが発生しました。
6
6
 
7
7
  ### 実現したいこと
8
8
 
@@ -12,9 +12,14 @@
12
12
 
13
13
  ```
14
14
  ActionController::ParameterMissing in PostsController#create
15
- param is missing or the value is empty: tag
15
+ param is missing or the value is empty: post
16
-
16
+ Did you mean?
17
+ controller
18
+ action
19
+ authenticity_token
20
+ Extracted source (around line #53):
21
+
17
- Rails.root: C:/Users/〇〇/Desktop/Smatch
22
+ rails.root: C:/Users/●●/Desktop/Smatch
18
23
 
19
24
  Application Trace | Framework Trace | Full Trace
20
25
  app/controllers/posts_controller.rb:53:in `post_params'
@@ -22,7 +27,7 @@
22
27
  Request
23
28
  Parameters:
24
29
 
25
- {"authenticity_token"=>"[FILTERED]", "post"=>{"tag"=>"インスタ", "time"=>"3"}, "commit"=>"保存"}
30
+ {"authenticity_token"=>"[FILTERED]"}
26
31
  Toggle session dump
27
32
  Toggle env dump
28
33
  Response
@@ -36,15 +41,15 @@
36
41
  ```rails
37
42
  private
38
43
  def post_params
39
- params.require(:tag).permit(:time)
44
+ params.require(:post).permit(:time, :tag)
40
45
  end
41
46
 
42
47
  end
43
48
  ```
44
49
 
45
- 大元のコードは以下のものになります。
50
+ ### 大元のコード
46
51
 
47
- rails posts_controller.rb
52
+ ##### rails posts_controller.rb
48
53
 
49
54
 
50
55
  before_action :authenticate_user!

1

該当コード以前のコードを掲載した。

2023/01/09 09:12

投稿

tyottomatetya1
tyottomatetya1

スコア0

test CHANGED
File without changes
test CHANGED
@@ -42,12 +42,72 @@
42
42
  end
43
43
  ```
44
44
 
45
+ 大元のコードは以下のものになります。
46
+
47
+ rails posts_controller.rb
48
+
49
+
50
+ before_action :authenticate_user!
51
+
52
+ def index
53
+ @posts = Post.all
54
+ if params[:tag]
55
+ Tag.create(name: params[:tag])
56
+ end
57
+ posts = Post.where(user_id: current_user.id)
58
+ @sum = posts.group(:tag).sum(:time)
59
+ end
60
+
61
+ def new
62
+ @post = Post.new
63
+ @tags = Tag.all
64
+ end
65
+
66
+ def create
67
+ post = Post.new(post_params)
68
+ if post.save
69
+ redirect_to :action => "index"
70
+ else
71
+ redirect_to :action => "new"
72
+ end
73
+ end
74
+
75
+ def show
76
+ @post = Post.find(params[:id])
77
+ end
78
+
79
+ def edit
80
+ @post = Post.find(params[:id])
81
+ end
82
+
83
+ def update
84
+ post = Post.find(params[:id])
85
+ if post.update(post_params)
86
+ redirect_to :action => "show", :id => post.id
87
+ else
88
+ redirect_to :action => "new"
89
+ end
90
+ end
91
+
92
+ def destroy
93
+ post = Post.find(params[:id])
94
+ post.destroy
95
+ redirect_to action: :index
96
+ end
97
+
98
+ private
99
+ def post_params
100
+ params.require(:post).permit(:time, :tag)
101
+ end
102
+
103
+ end
104
+
105
+
45
106
  ### 試したこと
46
107
 
47
108
  - データを保存するためのDBが作られているか確認
48
109
  - タグ名やカラム名が合っているか確認
49
110
  - chartkickに関する複数の資料を織り交ぜて機能をつけようとしてしまったので、1つの資料(「【Ruby on Rails】railsでスタディープラスっぽいもの作ろうとしてみた(グラフ表示)」,参考資料に記載)のみに絞ってやろうとしたが、うまくいかず。
50
-
51
111
 
52
112
  ### 参考にした資料
53
113