【发布时间】:2017-06-18 07:45:22
【问题描述】:
需要有关此错误的帮助。我无法弄清楚代码有什么问题。我在网上对相关主题进行了研究,但找不到任何解决方案。以下是代码。
<!-- 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为零。向我们展示您的welcome_controller -
我会更新代码更新上面的代码。
标签: ruby-on-rails model-view-controller crud