[英]Working through the 'Getting Started' for Ruby on Rails, but hit a wall on adding validation
决定本周末学习Ruby on Rails,所以今天早上我开始着手《 入门指南》 。
一切进展顺利,直到我到达了5.10节“添加一些验证”。 我相应地更新了模型和控制器,以及用于添加新帖子的视图,准确地遵循了它,并遇到了一个无法描述的错误: We're sorry, but something went wrong.
我检查了日志,这似乎表明文本的编码存在问题,因此我抛出了:
#!/bin/env ruby
# encoding: utf-8
在articles_controller.rb
的顶部,它揭示了这些错误:
undefined local variable or method ` ' for ArticlesController:Class
app/controllers/articles_controller.rb:9:in `<class:ArticlesController>'
app/controllers/articles_controller.rb:4:in `<top (required)>'
现在是我的articles_controller.rb
:
#!/bin/env ruby
# encoding: utf-8
class ArticlesController < ApplicationController
def new
@article = Article.new
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render 'new'
end
end
private
def article_params
params.require(:article).permit(:title, :text)
end
def show
@article = Article.find(params[:id])
end
def index
@articles = Article.all
end
end
我已按照本教程的原样进行操作,并尝试重做了几次,但这使我很困惑,因为我不知道为什么它说存在未定义的局部变量。 它与在articles_controller.rb
顶部定义文本编码articles_controller.rb
,还是我只是想念其他东西?
编辑我发现确实是一个用户提到的间距问题,所以我现在已经从一个错误转移到另一个错误。 谢谢大家,希望我能解决下一个问题。
尝试删除发生错误的位置附近的所有空格,并在自己中添加空格。
有时,当从在线复制代码时,这确实很奇怪。
(评论已移动)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.