找不到 UsersController 的操作 'news'
The action 'news' could not be found for UsersController
我正在学习 Michael Hartl 的 Rails 教程的第 7 章,在第 7.2 节中我想创建一个注册表单。这是我的 users_controller.rb 代码:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
end
这是我的 show.html.erb
<% provide(:title, @user.name) %>
<div class="row">
<aside class="col-md-4">
<section class="user_info">
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
</section>
</aside>
</div>
@Narges 我们了解到您正在阅读 Michael Hartle 的书,但是在所有与编程相关的出版物中,文本中通常都有错字。就像@GhostGambler 所说的那样,您正在某处调用 'news',而您的方法被称为 'new'。这就是导致错误的原因,新闻不在您的代码中的任何地方,而您正在调用它。找到调用它的位置并将其替换为 'new',您将看到错误消失,您的代码将产生所需的结果。
我正在学习 Michael Hartl 的 Rails 教程的第 7 章,在第 7.2 节中我想创建一个注册表单。这是我的 users_controller.rb 代码:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
end
这是我的 show.html.erb
<% provide(:title, @user.name) %>
<div class="row">
<aside class="col-md-4">
<section class="user_info">
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
</section>
</aside>
</div>
@Narges 我们了解到您正在阅读 Michael Hartle 的书,但是在所有与编程相关的出版物中,文本中通常都有错字。就像@GhostGambler 所说的那样,您正在某处调用 'news',而您的方法被称为 'new'。这就是导致错误的原因,新闻不在您的代码中的任何地方,而您正在调用它。找到调用它的位置并将其替换为 'new',您将看到错误消失,您的代码将产生所需的结果。