ruby 语法错误,意外的 $end,期待 keyword_end

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9905883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 04:56:32  来源:igfitidea点击:

syntax error, unexpected $end, expecting keyword_end

rubysyntax-error

提问by mancho1981

I am getting this error when trying to click a button with umlaut:

尝试单击带有变音符号的按钮时出现此错误:

syntax error, unexpected $end, expecting keyword_end
                click_on 'Neue Firma hinzufц╪gen'

I am testing with Ruby & Capabara.

我正在用 Ruby 和 Capabara 进行测试。

##Create_User_spec.rb 
require 'acceptance/acceptance_helper' 
## Feature 'Create User' 
feature 'Create User' do ## 
Scenario 'Create a User' 
scenario 'Create a User' do 
  ## Login into the service 
  visit 'url' 
  fill_in 'User-username', :with => 'test' 
  fill_in 'User-password', :with => 'test' 
  click_on 'login' 
  click_link 'Test' 
  click_on 'Neue Firma hinzufügen' 
end 
end

回答by Ben Phelps

This also can happen if you have a stray .trailing a method, so check for those as well.

如果您有一个杂散的.跟踪方法,也会发生这种情况,因此也请检查这些。

回答by Fabio CR

It happened to me because of special characters, in my case portuguese signs. I believe the problem is the "ü" in hinzufügen. Looking for a solution yet.

它发生在我身上是因为特殊字符,在我的情况下是葡萄牙语标志。我相信问题出在 hinzufügen 中的“ü”。还在寻找解决方案。

Edit: found a solution!

编辑:找到了解决方案!

I added the following to the very top of the rb file:

我在 rb 文件的最顶部添加了以下内容:

# encoding: utf-8

# 编码:utf-8

(don't miss the # sign, it is needed)

(不要错过#号,它是必需的)

回答by Kashiftufail

This error due to an extra end.Mean you have written an extra end with no matching do.

这个错误是由于一个额外的结尾。意味着你写了一个没有匹配的额外结尾。

回答by Sean Dunford

This happened to me as well but because I was missing an end. I am following this tutorial

这也发生在我身上,但因为我错过了结局。我正在关注本教程

http://tutorials.jumpstartlab.com/projects/blogger.html

http://tutorials.jumpstartlab.com/projects/blogger.html

My model was:

我的模型是:

class ArticlesController < ApplicationController
    def index
     @articles = Article.all
    end

It needed to be:

它必须是:

class ArticlesController < ApplicationController
    def index
     @articles = Article.all
    end 
end

Hope that helps someone.

希望能帮助某人。