ruby-on-rails - NameError: 未初始化的常量GoalsController::Goal ruby-on-rails
问题描述
我正在制作一个网站,它将跟踪用户的目标。我目前在尝试创建模型对象以将表单字段绑定到时遇到 NameError。
当我在大多数情况下查找此错误时,情况是相同的,但是他们使对象复数(又名@goal =Goals.new),而这里的情况并非如此。我的另一个侧面查询是在 form_for 标记中,通常指定一个 url。在我的情况下,我通常会将其设为目标#create(POST 请求)的路径,但我的路由没有显示此 url 的帮助程序/路径。提前致谢。
这是控制器的goals_controller.rb:
class GoalsController < ApplicationController
# GET request to /goals/new
def new
@goal = Goal.new
end
# GET request to /goals
def index
end
end
完整错误: Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms)
NameError (uninitialized constant GoalsController::Goal):
app/controllers/goals_controller.rb:4:in `new'
Rendering /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-5.0.7.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
Rendering /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-5.0.7.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-5.0.7.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (2.3ms)
Rendering /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-5.0.7.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-5.0.7.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.2ms)
Rendering /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-5.0.7.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-5.0.7.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.6ms)
Rendered /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-5.0.7.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (14.8ms)
解决方案
推荐阅读
- javascript - 在 Angular 4 打字稿上加载外部网络库
- pandas - ImportError:没有名为“pandas.testing”的模块
- javascript - 对象属性之间的 Angular FormArray 交叉验证
- arrays - 显示来自 API In Angular 6 页面的值
- java - 如何解析 asString() 唯一响应
- wordpress - 使用 Imagick 在 Wordpress 中自定义缩略图
- javascript - JavaScript 使用 for 循环创建新元素
- angular - 多张图片上传到 Spring Boot
- node.js - 一段时间后从云功能发送通知
- ios - 播放视频时使用avplayerkit问题黑屏来了