Screenshot PhotoWelcome#indexのNoMethodError - Rails入門
このエラーのヘルプが必要です。私はコードに何が間違っているのか分かりません。関連トピックをオンラインで調査しましたが、解決策が見つかりません。以下はそのコードです。
<!-- index.html.erb -->
<h1>Hello, Rails!</h1>
<%= link_to 'My Blog', controller: 'articles' %>
<%= link_to 'New article', new_article_path %>
<table>
<tr>
<th>Title</th>
<th>Text</th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
<td><%= link_to 'Show', article_path(article) %></td>
<td><%= link_to 'Edit', edit_article_path(article) %></td>
<td><%= link_to 'Destroy', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
ここはコントローラのコードです。
# welcome_controller.rb
class WelcomeController < ApplicationController
def index
end
end
コンフィグコード
# routes.rb
Rails.application.routes.draw do
get 'welcome/index'
resources :articles
root 'welcome#index'
end
任意の助けいただければ幸いです!ゼロのための未定義のメソッド各
'@ articles'はnilです。私たちにあなたの 'welcome_controller'を表示してください – Pavan
上記のコードを更新するコードを更新します。 – jamespd