jjzjj

my_function

全部标签

ruby-on-rails - 为什么要测试:units and test:functionals insist on running in development environment?

我正在尝试测试一些特定于环境的设置(特定于中间件,但这似乎无关紧要),但我无法让测试在正确的环境中运行。症状:如果我运行rubytest/unit/my_test.rb,一切都很好,因为它做的第一件事是需要test/test_helper.rb,这会设置环境"test"然后加载Rails环境。如果我运行raketest,第一批(功能)运行良好,但第二批(单元)失败。失败是ENV['RAILS_ENV]以某种方式在批处理之间未设置,然后config/environment.rb看到没有设置并使用默认值"development“。环境在config/environment.rb的开头和该文

ruby - 了解 [ClassOne, ClassTwo].each(& :my_method)

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:Whatdoesmap(&:name)meaninRuby?我在观看railscast时看到了这段代码。[Category,Product].(&:delete_all)关于清除数据库。我在IRC中询问了线路,并被告知(&:delete_all)是的捷径{|model|model.delete_all}我用下面的测试了这个classClassOnedefclass_methodputs1endendclassClassTwodefclass_methodputs2endend[ClassOne,ClassTw

ruby - RVM + Zsh "RVM is not a function, selecting rubies with ' rvm 使用.. .' will not work"

首先我要说我不是命令行专家,所以我真的几乎不知道自己在做什么。我无法让RVM和oh-my-zsh一起玩得很好。我尝试了几种不同的解决方案,其中一些是在SO上发布的,但我发现似乎没有任何解决方案可以解决问题。最初,其他人在我的机器上安装了RVM。后来我自己设置了oh-my-zsh,记得当时遇到了很多麻烦。除了这两行,我的.zhsrc文件是完全默认的exportPATH=$HOME/bin:/usr/local/bin:/usr/local/rvm/bin:$PATH#prettysurethislinedoesnothing,althoughI'veseenthisfixaround#s

ruby-on-rails - 停用 Gem - "you have already activated rake 0.9.3.beta.1, but my Gemfile requires rake 0.9.2"

我正在尝试运行迁移,但我不断收到错误消息:rakeaborted!Undefinedmethodprerequisitefornil:NilClass.似乎我以某种方式激活了一个名为rake0.9.3.beta.1的gem-但是我已经更改了gembundleinstall并运行bundleshowrake并且它显示安装了rake0.9.2。我是第一次使用Git,所以我认为这可能与仍在使用测试版rake的应用程序有关-但我已经完成了推送,它显示gemfile已更新。当我向下查看gem库时,我只能看到rake0.9.2版本。我应该看哪里?我还有一条Rails:Railtie弃用警告-但我认

ruby-on-rails - cucumber + capybara : Problem with a scenario that redirects the browser outside of my app

GivenIhavearailsappAndI'musingcucumberAndI'musingcapybaraAndIhaveanactionthatresultsinaredirect_to"http://some.other.domain.com/some_path"WhenItestthisactionThenthein-appportionofthetestworksfineButIseethiserror:Noroutematches"/some_path"with{:method=>:get}(ActionController::RoutingError)所以capyb

ruby-on-rails - rails : Why images are not showing in my rails basic app

我的index.html.erb代码-Listingproducts'list_image')%>图像在app\assets\images下..但是前端没有显示静态图像。当我Firebug它时,我相信图像标签是正确形成的...让我知道我在这部分缺少什么。截图-图片也到位了-让我知道我做错了什么,我该如何解决。编辑github.com/swapnesh/depot请告诉我为什么它在我的案例中不起作用。尽管更改/images/product1.jpgTo/assets/product1.jpg使其正常工作。 最佳答案 如果您正在使用As

ruby - 我在 Mac OS X 上收到 "RVM is not a function"错误,并且没有发布的解决方案有效

我在MacOSx10.8.2(“MountainLion”)上,我成功安装了RVM1.17.8及其依赖项。我可以使用它来使用rvminstall1.9.2安装Ruby版本,但我无法执行rvmuse没有收到此错误:RVMisnotafunction,selectingrubieswith'rvmuse...'willnotwork.Youneedtochangeyourterminalemulatorpreferencestoallowloginshell.Sometimesitisrequiredtouse`/bin/bash--login`asthecommand.Pleasevis

ruby - "RVM is not a function"错误

RVM已正确安装在我的机器上(运行MacOSX10.6.8)并且运行良好。奇怪的是,要运行它,我必须为每个新session使用source~/.rvm/scripts/rvm。我尝试从它创建一个符号链接(symboliclink)到/opt/local/bin/rvm,但是当它运行时它什么也不做。我还尝试创建一个从~/.rvm/bin/rvm到/opt/local/bin/rvm的符号链接(symboliclink),当我运行rvm在终端中,它会按预期显示帮助页面。但是当我尝试rvmusesome_ruby_version时,它总是显示“RVM不是一个函数,选择带有‘rvmuse...

ruby - "extend self"与 "module_function"相同吗?

extendself和module_function是实现它的两种ruby​​方法,因此您可以在模块上调用方法,如果包含该模块也可以调用它。这些方式的最终结果有什么不同吗? 最佳答案 module_function将给定的实例方法设为私有(private),然后复制并将它们作为公共(public)方法放入模块的元类中。extendself将所有实例方法添加到模块的单例中,保持它们的可见性不变。moduleMextendselfdefa;endprivatedefb;endendmoduleNdefc;endprivatedefd;e

ruby-on-rails - rails : I can't call a function in a module in/lib - what am I doing wrong?

我有一个模块保存在/lib中作为test_functions.rb看起来像这样moduleTestFunctionsdefabcputs123endend进入ruby​​脚本/运行程序,我可以看到该模块正在自动加载(良好的配置约定等等......)>>TestFunctions.instance_methods=>["abc"]所以方法是已知的,让我们尝试调用它>>TestFunctions.abcNoMethodError:undefinedmethod`abc'forTestFunctions:Modulefrom(irb):3没有。这个怎么样?>>TestFunctions::a