前提
Railsでスマホアプリの利用時間をアプリジャンルごとにグラフ化させるアプリを開発しています。
現在は、入力した値(使用アプリ名や利用時間など)をChartkickという機能を用いてグラフ化させようとしている段階です。
グラフが表示されるページに戻るボタンを押した際に以下のエラー文が発生しました。
実現したいこと
- 入力したデータが正常に保存できるようにする
発生している問題・エラーメッセージ
ActionController::ParameterMissing in PostsController#create param is missing or the value is empty: post Did you mean? controller action authenticity_token Extracted source (around line #53): rails.root: C:/Users/●●/Desktop/Smatch Application Trace | Framework Trace | Full Trace app/controllers/posts_controller.rb:53:in `post_params' app/controllers/posts_controller.rb:20:in `create' Request Parameters: {"authenticity_token"=>"[FILTERED]"} Toggle session dump Toggle env dump Response Headers: None
該当のソースコード
rails
1 private 2 def post_params 3 params.require(:post).permit(:time, :tag) 4 end 5 6end
大元のコード
rails posts_controller.rb
before_action :authenticate_user!
def index
@posts = Post.all
if params[:tag]
Tag.create(name: params[:tag])
end
posts = Post.where(user_id: current_user.id)
@sum = posts.group(:tag).sum(:time)
end
def new
@post = Post.new
@tags = Tag.all
end
def create
post = Post.new(post_params)
if post.save
redirect_to :action => "index"
else
redirect_to :action => "new"
end
end
def show
@post = Post.find(params[:id])
end
def edit
@post = Post.find(params[:id])
end
def update
post = Post.find(params[:id])
if post.update(post_params)
redirect_to :action => "show", :id => post.id
else
redirect_to :action => "new"
end
end
def destroy
post = Post.find(params[:id])
post.destroy
redirect_to action: :index
end
private
def post_params
params.require(:post).permit(:time, :tag)
end
end
試したこと
- データを保存するためのDBが作られているか確認
- タグ名やカラム名が合っているか確認
- chartkickに関する複数の資料を織り交ぜて機能をつけようとしてしまったので、1つの資料(「【Ruby on Rails】railsでスタディープラスっぽいもの作ろうとしてみた(グラフ表示)」,参考資料に記載)のみに絞ってやろうとしたが、うまくいかず。
参考にした資料
「【Ruby on Rails】railsでスタディープラスっぽいもの作ろうとしてみた(グラフ表示) 」
https://qiita.com/Yu_unI1/items/c3c977288054560fe0e6
「Chartkickを使って、グラフを作成してみた」
https://qiita.com/pyon_kiti_jp/items/3fda2f9274cbbe6252da

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/01/09 08:36 編集
2023/01/09 08:37
2023/01/09 09:47 編集