草庐IT

undefined-symbol

全部标签

ruby - 无法将 Symbol 转换为 String

我有以下Ruby代码,直接取自GettingStartedwithRails指南defcreate@post=Post.new(post_params)@post.saveredirect_to@postendprivatedefpost_paramsparams.require(:post).permit(:title,:text)end当我运行上面的Create时,出现以下错误。can'tconvertSymbolintostring 最佳答案 您似乎正在尝试使用强参数。你得到这个错误cannotconvertsymbolint

ruby-on-rails - Rails 3.1 和 Ruby 1.9.3p125 : ruby-debug19 still crashes with "Symbol not found: _ruby_threadptr_data_type"

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:ruby-debugwithRuby1.9.3?我听说ruby​​1.9.3p125有解决ruby​​-debug19问题的传言,所以根据RVM站点上的说明,我重新安装了1.9.3:$rvmreinstall1.9.3--patchdebug--force-autoconf$ruby-vruby1.9.3p125(2012-02-16revision34643)[x86_64-darwin11.2.0]然后:geminstallruby-debug19将此条目添加到我的Gemfile中:gem'ruby-de

ruby - 如何使 Ruby 的 Find.find 遵循符号链接(symbolic link)?

我有一个文件层次结构,一些子目录是相对符号链接(symboliclink)。我正在使用Ruby'sFind.find爬取这些目录并找到一些特定文件。但是,它不会查看任何作为符号链接(symboliclink)的目录(它跟随作为符号链接(symboliclink)的文件)。查看sourcecode看来问题是因为它正在使用File.lstat(file).directory?来测试某物是否是目录。这对符号链接(symboliclink)返回false但File.stat.directory?返回true。如何让Find.find跟随符号链接(symboliclink),而不是猴子修补它以使

ruby - Capistrano 检查任务中 undefined variable

在使用多阶段扩展的Capistrano中,我有两个环境:生产和测试。我在testing.rb中需要一些在prod.rb中不需要的变量,我希望我的一些任务能够检查变量是否已定义并在定义时使用它,但在定义时忽略它未设置。所以,在testing.rb中,我会有类似的东西:set:foo,'bar'prod.rb不会引用:foo因为它不需要它。在我的一项任务中,我想做类似的事情:ifdefined?(foo)#dosomethingwithfooelse#dosomethingwithoutfooend但我一直收到错误:undefinedlocalvariableormethod'foo'有没

Ruby Koans #75 test_constants_become_symbols,正确答案?

我的问题基于这个问题:RubyKoan:Constantsbecomesymbols.我有以下代码:in_ruby_version("mri")doRubyConstant="Whatisthesoundofonehandclapping?"deftest_constants_become_symbolsall_symbols=Symbol.all_symbolsassert_equal__,all_symbols.include?(__)endend正确答案应该是下面的吗?assert_equaltrue,all_symbols.include?("RubyConstant".to_

ruby - 为什么没有更多的项目使用 Ruby Symbols 而不是 Strings?

当我第一次开始阅读和学习ruby​​时,我读到了一些关于ruby​​符号相对于字符串的强大功能:符号只在内存中存储一​​次,而字符串每个字符串在内存中存储一​​次,即使它们是相同的。比如:Rails的paramsHash在Controller中有一堆key作为符号:params[:id]orparams[:title]...但是Sinatra和Jekyll等其他规模适中的项目不会这样做:杰基尔:post.data["title"]orpost.data["tags"]...西纳特拉:params["id"]orparams["title"]...这使得阅读新代码变得有些棘手,并且难以转

ruby - 为什么 Ruby 会在线上为最后一个 undefined variable 引发错误?

假设foo、bar和baz没有定义,行foobarbaz引发此错误:NameError(main:Object的未定义局部变量或方法“baz”)在Python、PHP和Javascript的REPL中,foo(bar(baz))中的第一个问题是未定义foo。为什么Ruby首先提示baz? 最佳答案 Ruby允许调用的第一个方法(baz)动态定义其他两个方法。在实际方法调用发生之前,它不会尝试将foo或bar解析为方法调用,并且它永远不会作为baz到达该方法调用首先导致错误。如果baz动态定义方法foo和bar,没有问题:defbaz

ruby 公案 : Constants become symbols

在about_symbols.rbRubyKoan(https://github.com/edgecase/ruby_koans)中,我有以下代码:RubyConstant="Whatisthesoundofonehandclapping?"deftest_constants_become_symbolsall_symbols=Symbol.all_symbolsassert_equaltrue,all_symbols.include?(:"nonexistent")assert_equaltrue,all_symbols.include?(:"Whatisthesoundofoneh

ruby-on-rails - 在 Rails 3.2 中使用 "error_messages"? (引发 "undefined method"错误)

我在Rails3.2功能测试中遇到以下错误:ActionView::Template::Error:undefinedmethod`error_messages'for#产生错误的View代码:#problematiccode这是我的Controller中调用上述View代码的代码:render:action=>"edit",:status=>:bad_request这是我正在运行的测试:test"updateaprogramwithabadrequest"doput:update,:id=>programs(:traditional).to_param,:program=>{:min

ruby-on-rails - Ruby/Rails 神秘的 "undefined constant"问题

我有一个Rails项目,其中一个常量在处理请求时在某个时刻被破坏。我正在使用mime/types和restclientgem。restclient模块定义了MIME的扩展,其中包含type_for_extension方法。moduleRestClient...defstringify_headersheadersresult[key]=target_values.map{|ext|MIME::Types.type_for_extension(ext.to_s.strip)}.join(',')...endendendmoduleMIMEclassTypesdeftype_for_ext