[英]Error on Ruby on Rails tutorial
我尝试做Rails入门教程,但有一个我不明白的问题。
我尝试执行第5.10部分 ,使用更新功能添加一些验证 ,但出现错误“很抱歉,出了点问题。” 没什么...
我为所有代码感到抱歉,但是我是一个初学者,我真的不知道错误在哪里:/
控制器:
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def new
@article = Article.new()
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render 'new'
end
end
def show
@article = Article.find(params[:id])
end
def edit
@article = Article.find(params[:id])
end
def update
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to @article
else
render 'edit'
end
end
private
def article_params
params.require(:article).permit(:title, :text)
end
如果我删除更新功能上的if / else / end,它就可以工作(输入其他错误,不仅是抱歉的消息)
----------------- [ 编辑 ] --------------------
我已经阅读了日志文件,并且我认为这一行可以为您提供帮助:/
Started GET "/articles" for 127.0.0.1 at 2014-05-22 14:06:02 -0400
SyntaxError (C:/Users/Stephane/Desktop/rails_projects/fist_app/app/controllers/articles_controller.rb:32: invalid multibyte char (US-ASCII)
C:/Users/Stephane/Desktop/rails_projects/fist_app/app/controllers/articles_controller.rb:32: syntax error, unexpected $end, expecting keyword_end
else
^):
您的文本中可能有一个不可见的控制字符(可能是剪切和粘贴)。 尝试删除if / else语句,然后手动重新输入。 我知道这听起来很奇怪,但已经多次看到这种事情发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.