LoginSignup
1
1

More than 5 years have passed since last update.

【Rails】Viewにモデルのデータ一覧が表示されるバグとその対処法

Posted at

なんてことはない対処法だったけど、初めて見ると戸惑ったので覚書として投稿。

Railsで記事投稿機能の実装に関する基本的な演習をしていると、
エラーこそ表示されないが、身に覚えのないテキストがこのように表示された。(画像の青枠の部分。)

スクリーンショット 2018-08-17 19.46.57.jpg

Viewの記述はこちら

<h1>投稿一覧</h1>
<%= link_to '新規投稿', posts_new_path %>
<%= link_to 'ログアウト', destroy_user_session_path, method: :delete %>
<br>
<%= @posts.each do |t| %>
<%= t.title %>
<br>
<% end %>

5行目、イコールが不要でした。訂正すると、

<h1>投稿一覧</h1>
<%= link_to '新規投稿', posts_new_path %>
<%= link_to 'ログアウト', destroy_user_session_path, method: :delete %>
<br>
#ここのイコールが悪さしてた様子
<% @posts.each do |t| %>
<%= t.title %>
<br>
<% end %>

post.jpeg

無事解決。エラーとして表示されないので、文法的にどのように解釈されているのか気になる。。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1