Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 语法错误,意外'';,应为';)';带栏杆4_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 语法错误,意外'';,应为';)';带栏杆4

Ruby on rails 4 语法错误,意外'';,应为';)';带栏杆4,ruby-on-rails-4,Ruby On Rails 4,Rails 4.1和Ruby 2.0 以下是lib/global_methods.rb中的内容: def admin_status? (id = nil) role_value = I18n.t 'admin_role' unless id current_user.role == role_value else determine_user_role (id, role_value) end end def determine_user_role (id, r

Rails 4.1和Ruby 2.0

以下是lib/global_methods.rb中的内容:

def admin_status? (id = nil)
  role_value = I18n.t 'admin_role'
  unless id
    current_user.role == role_value
  else
    determine_user_role (id, role_value)
  end
end

def determine_user_role (id, role_value)
  user = User.find_by id: id
  user.role == role_value
end
下面是我在application_controller.rb中的内容

class ApplicationController < ActionController::Base

  protect_from_forgery with: :exception

  require ('json')
  require ('csv')
  require ('global_methods')

end

它指出应用程序_controller.rb中的第7行是罪魁祸首。如果从global_method.rb中删除函数,我将不再得到错误。我看不出语法问题。有什么想法吗?

它在抱怨你的I18n翻译。当我重写代码时,将determine_user_role()的定义放在global_methods.rb中admin_status?()的定义之前,而不是仅仅使用标准字符串进行“admin_role”的I18n翻译,这样做很好

不幸的是,我不太熟悉i18ngem,也不太熟悉您需要如何为Rails环境插入和配置i18ngem,因此我无法在这里为您提供完整的答案。您的问题中没有足够的信息可供了解。

调用方法名称和任何括号之间有空格的多参数方法不再有效(因为我相信
1.8.7
):

~>rvm 1.8.7
~>ruby-ve'def bs(a,b)end;bs(1,2)'
ruby 1.8.7(2013-06-27 patchlevel 374)[i686-darwin12.5.0]
-e:1:警告:不要在参数括号前加空格
~>rvm 2.1.1
~>ruby-ve'def bs(a,b)end;bs(1,2)'
ruby 2.1.1p76(2014-02-24修订版45161)[x86_64-darwin12.0]
-e:1:语法错误,意外“,”,应为“)”
def bs(a、b);结束;bs(1,2)
^
-e:1:警告:在无效上下文中可能无用地使用文字
~>ruby-ve'def bs(a,b)end;bs(1,2)'
ruby 2.1.1p76(2014-02-24修订版45161)[x86_64-darwin12.0]

下面是另一个涉及到ruby语法的例子。

没有严格的关联,但基本上没有人把参数放在
require
周围。我不建议这样做,因为它的可读性。是的,我一开始没有偏执狂,但在我复制代码的时候,我花了大约一个小时尝试不同的方法来诊断这个问题。我将回到没有巴拉那人。更具可读性是的,这解决了问题。I18n是核心rails环境的一部分,配置/设置没有太多内容。它是可用的“开箱即用”没有任何设置。问题也不是I18n,而是在方法名和围绕参数的括号之间有一个空格。如果这样做,RubyPost1.8就会失败。使用I18n与为代码编写函数一样重要。为了它的价值,我在Rails外部运行了代码,没有空间。尝试使用i18n翻译时,我得到了报告的语法错误。没有尝试翻译,效果很好。因此,根据您所处的环境,代码中的两种不同内容可能会产生与您相同的错误。Ruby translator的错误报告没有指定实际有问题的代码行,而是指定对所需外部文件的引用,这也没有帮助。
syntax error, unexpected ',', expecting ')'