简体   繁体   English

Ruby on Rails教程错误

[英]Error on Ruby on Rails tutorial

I try to do the Getting Started with Rails tutoriel and I have a problem I don't understand.. 我尝试做Rails入门教程,但有一个我不明白的问题。

I trying to do the part 5.10 Adding Some Validation with the update function but i have an error "We're sorry, but something went wrong." 我尝试执行第5.10部分 ,使用更新功能添加一些验证 ,但出现错误“很抱歉,出了点问题。” and nothing else... 没什么...

I'm sorry for all the code, but i'm a begginer and i realy don't know where is the error :/ 我为所有代码感到抱歉,但是我是一个初学者,我真的不知道错误在哪里:/

The controller : 控制器:

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

And if i delete the if/else/end on the update function, it's work (put an other error but not only the sorry message) 如果我删除更新功能上的if / else / end,它就可以工作(输入其他错误,不仅是抱歉的消息)

-----------------[ EDIT ]-------------------- ----------------- [ 编辑 ] --------------------

I have read the log file and I think this line can help you :/ 我已经阅读了日志文件,并且我认为这一行可以为您提供帮助:/

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
 ^):

You probably have an invisible control character in your text (perhaps from cut and paste). 您的文本中可能有一个不可见的控制字符(可能是剪切和粘贴)。 Try deleting the if/else statement and retype it by hand. 尝试删除if / else语句,然后手动重新输入。 I know this sounds strange but have seen this kind of thing happen many times. 我知道这听起来很奇怪,但已经多次看到这种事情发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM