jjzjj

set-variable

全部标签

ruby-on-rails - RSpec 应用程序助手测试 : Undefined local variable or method `helper`

有一段时间这似乎是一个闪烁的错误,但现在它一直出现:当我在一个相当简单的ApplicationHelper规范上运行RSpec时,我得到以下错误:%rspec--backtrace1)ApplicationHelperrendersMarkdownfromplaintextFailure/Error:expect(helper.md(plaintext)).toeq("Header\n")NameError:undefinedlocalvariableormethod`helper'for##/Users/danielsh/.rvm/gems/ruby-2.1.1@project-st

ruby - 厨师和 ruby : how to convert a array into a set

我有一个如下所示的数组:nodes=['server1','server1','server2']在厨师食谱中,我需要在传递给模板erb之前将其转换为集合。我该怎么做? 最佳答案 此模式适用于Set、Matrix、JSON等;这是尝试的第一件事。require'set'nodes=['server1','server1','server2']pnodes.to_set## 关于ruby-厨师和ruby:howtoconvertaarrayintoaset,我们在StackOverflow

ruby - 警告 : PATH set to RVM ruby but GEM_HOME and/or GEM_PATH not set, 请参阅 : https://github. com/wayneeseguin/rvm/issues/3212

我每次打开终端时都会收到这个错误:警告:PATH设置为RVMruby​​但未设置GEM_HOME和/或GEM_PATH,请参阅:https://github.com/wayneeseguin/rvm/issues/3212这是在我最近安装zsh(oh-my-zsh)后开始发生的我不知道如何设置GEM_HOME和/或GEM_PATH的路径。 最佳答案 我也面临同样的问题,更改.zshrc中的以下行,exportPATH="/usr/local/heroku/bin:.........."到exportPATH="$PATH:/usr/

ruby-on-rails - 每当 gem : I set :output but the logfile doesn't show up where I'd expect it to

在我的schedule.rb文件中,我有以下几行:set:output,'/log/cron_log.log'every5.minutesdocommand'echo"hello"'end我按照这个问题Rails,usingwhenevergemindevelopment中的建议运行了whenever-w,并且我假设cronfile已编写并正在运行。(我也尝试重新启动Rails服务器。)当我运行$crontab-l时,我看到以下内容:0,5,10,15,20,25,30,35,40,45,50,55****/bin/bash-l-c'echo"hello">>/log/cron_log

ruby-on-rails - rails : How can you access session variables using multiple controllers?

我在使用session变量时遇到问题。我有两个名为“graduate_students_controller”和“current_students_controller”的Controller。这些Controller中的每一个都控制不同的View文件。我在这两个Controller中使用session变量来存储session信息。问题来了。假设我有两个View文件“reports/current_students_list”、“reports/graduate_students_list”,每个文件都由上述Controller单独控制。现在,如果我尝试从同一浏览器中打开这两个网页并尝

ruby-on-rails - 如何在 RubyOnRails 中使用 'acts as nested set' 创建一个可排序的接口(interface)

我一直在为使用acts_as_list的模型实现一些不错的交互界面,这些界面可以对我的mRails应用程序中的列表进行排序。我有一个排序函数,在每次拖放之后使用sortable_elementscript.aculo.us函数调用并设置每条记录的位置。这是在拖放完成后处理排序的Controller操作示例:defsortparams[:documents].each_with_indexdo|id,index|Document.update_all(['position=?',index+1],['id=?',id])endend现在我正在尝试对嵌套集模型(acts_as_nested

c - (U) Ruby 扩展 : rb_gc_mark() and instance variables

我正在编写定义类的ruby​​扩展。如果我使用Data_Wrap_Struct()来实现我对rb_define_alloc_func()的回调,我是否需要手动标记和释放实例变量?还是仍然为我处理? 最佳答案 Ruby的GC将收集在您的Ruby对象的实例变量中引用的所有Ruby对象。您不必也不应该自己释放Ruby实例变量(即在您的扩展中使用rb_iv_set()/rb_iv_get()访问的任何对象)。但是,如果包装的Cstruct引用Ruby对象,那么您必须在传递给Data_Wrap_Struct()的mark回调中标记这些对象。(

ruby - 名称错误 : undefined - have parsing rules for local variables changed in Ruby 2. 1.2?

我得到NameError:undefinedlocalvariableormethodwithruby​​2.1.2正如在thisquestion中观察到的那样,表达式如:barifbar=true引发未定义的局部变量错误(前提是bar之前未定义),因为bar在分配之前被解析器读取。而且我相信以前用这个表达式没有什么区别:barifbar=false两者之间的区别在于主体是否被求值,但如果遇到未定义的局部变量会在求值条件之前立即引发错误,那应该无关紧要。但是当我在Ruby2.1.2上运行第二个代码时,它没有引发错误。以前也是这样吗?如果是这样,那么解析讨论的内容是什么?如果没有,Rub

ruby - Sinatra 应用程序中的错误 "undefined local variable or method ` logger '"when using ` logger.info`

我有以下Sinatra1.2.1应用程序代码:#app.rbrequire'sinatra'get'/'dologger.info"COUCOU"'Helloworld!'end并使用ruby-rubygemsapp.rb启动服务器。当我转到http://localhost:4567时出现错误:NameErrorat/undefinedlocalvariableormethod`logger'for#file:app.rblocation:blockinline:4我是否需要添加或配置一些东西才能在Sinatra中启用日志记录?阅读SinatraREADME和文档,似乎默认情况下为Si

ruby - 为什么我可以在 Ruby 中将一个 undefined variable 赋值给它自己并得到 nil?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whya=aisnilinRuby?我们应该说,在Ruby中使用undefinedvariable是“奇怪的现象”。是这样的:#irbsessionfollows#foo#undefinedlocalvariableormethod'foo'bar#samefor'bar'foo=bar#stillsamefor'bar'foo=foo#nil-HUH?foo#isnowsettonil!?为什么我可以在Ruby中将一个undefinedvariable赋值给自身并得到nil?请注意,我在这里使用的是Ruby