NameError Link 我尝试使用+-----------+---------+
| StarType | Planets |
+-----------+---------+
| G2V | 3 |
| Red Dwarf | 2 |
+-----------+---------+
启动我的ruby应用程序。在此之前,我使用了rails server
。在http://localhost:3000/
尝试检查config文件夹下的index.html.erb和application.html.erb文件以及route.rb文件
routes.rb
$ rails generate controller simple_pages index
index.html.erb
Rails.application.routes.draw do
root 'simple_pages#index'
get 'index', to: 'simple_pages#index'
end
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>R2</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<nav>
<ul>
<li><%= link_to "Home",root_path %></li>
<li><%= link_to "About",simple_pages_about_path %></li>
<li><%= link_to "Contact",simple_pages_contact_path %></li>
</ul>
</nav>
<%= yield %>
</<footer>
© 2018 Bike Berlin
</footer>
</body>
</html>
该页面应显示无错误。
堆栈跟踪如下
<p id="notice"><%= notice %></p>
<h1>Simple Pages</h1>
<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @simple_pages.each do |simple_page| %>
<tr>
<td><%= link_to 'Show', simple_page %></td>
<td><%= link_to 'Edit', edit_simple_page_path(simple_page) %></td>
<td><%= link_to 'Destroy', simple_page, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Simple Page', new_simple_page_path %>
答案 0 :(得分:2)
您没有相应的路线/帮手(从我们的视野中可以看到)。您需要在routes.rb
中执行此操作 resources :simple_pages
答案 1 :(得分:0)
请按照以下步骤操作:
rails g controller simple_pages
root 'simple_page#index'
resources :simple_pages
class SimplePageController < ApplicationController
def index
end
end
答案 2 :(得分:-1)
在routes.rb中替换以下内容。rb get 'simple_pages/index'
错误的get 'index', to: 'simple_pages#index'
应该是这样的