実現したいこと
ここに実現したいことを箇条書きで書いてください。
- time_formats.rbを利用してフォーマットを使った日時の表示をしたい。
前提
dockerでRuby on Rails7の環境を使って簡単な掲示板のアプリの作成練習をしています。
発生している問題・エラーメッセージ

ArgumentError in Boards#index Showing /app/app/views/boards/index.html.erb where line #23 raised: wrong number of arguments (given 1, expected 0)
該当のソースコード
config/initializers/time_formats.rb
1Time::DATE_FORMATS[:datetime_jp] = '%Y年%m月%d日 %H時%M分'
app/views/boards/index.html.erb
1<div class="d-flex align-items-center"> 2 <h1>掲示板一覧</h1> 3 <div class="ms-auto boards__linkBox"> 4 <a href="/boards/new" class="btn btn-outline-dark">新規作成</a> 5 </div> 6</div> 7<table class="table table-hover boards__table"> 8 <thead class="table-dark"> 9 <tr> 10 <th>ID</th> 11 <th>タイトル</th> 12 <th>作成者</th> 13 <th>作成日時</th> 14 <th>更新日時</th> 15 </tr> 16 </thead> 17 <tbody> 18 <% @boards.each do |board| %> 19 <tr> 20 <th><%= board.id %></th> 21 <th><%= board.title %></th> 22 <th><%= board.author_name %></th> 23 <th><%= board.created_at.to_s(:datetime_jp) %></th> 24 <th><%= board.updated_at.to_s(:datetime_jp) %></th> 25 </tr> 26 <% end %> 27 </tbody> 28</table>
app/controllers/boards_controller.rb
1class BoardsController < ApplicationController 2 def index 3 @boards = Board.all 4 end 5 6 def new 7 @board = Board.new 8 end 9 10 def create 11 Board.create(board_params) 12 end 13 14 private 15 16 def board_params 17 params.require(:board).permit(:author_name, :title, :body) 18 end 19 20end 21
試したこと
タイポがないか、参考の動画と比較してみました。
またdocker compose stopで一度railsを停止させて再度起動させてみました。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。

0 コメント