草庐IT

first_run

全部标签

ruby - 如何通过 docker-compose run 使用 Docker 访问 Sinatra 端口

我不确定如何正确地将Sinatra端口4567从Docker公开回主机。在本地运行应用程序没有问题。以下存储库显示了https://gitlab.com/davidhooey/sinatra-docker问题的案例通过搜索,我注意到以下问题RunningRubySinatrainsideaDockercontainernotabletoconnect(viaMachost)orfindcommands(indifferentscenario)?,其中--host0.0.0.0被传递到rackup命令中。但是,我通过使用Site.run!以编程方式启动网站。文件树.├──Dockerfi

ruby Enumerable#first vs #take

rubyEnumerable/Arrayfirst(n)和take(n)有什么区别?我依稀记得take与惰性评估有关,但我不知道如何使用它来做到这一点,也找不到任何有用的谷歌搜索或文档。“take”是一个很难用谷歌搜索的方法名称。first(n)和take(n)是documented完全相同,不是太有帮助。first→objornilfirst(n)→an_arrayReturnsthefirstelement,orthefirstnelements,oftheenumerable.Iftheenumerableisempty,thefirstformreturnsnil,andthe

ruby - 在 emacs 中运行 irb(通过 run-ruby)会回显我输入的所有内容

我正在运行WindowsVista和Emacs23.1.1,并且我已经使用“一键式Ruby安装程序”安装了Ruby。然后,我按照inf-ruby.el中的指定安装了与Ruby一起安装的EmacsLisp文件。当我运行run-ruby(M-xrun-ruby)函数时,irb启动,但每次我按Enter时,irb都会打印出我刚刚输入的行。例如:irb(main):001:0>deffoo()deffoo()3+43+4endendnil这很烦人。如果我只是在cygwin命令shell中运行irb,则不会执行回显。例如:$irb.bat--inf-ruby-modeirb(main):001:

ruby-on-rails - 如何将 joins 方法与 first_or_initialize 一起使用而不是 find_or_initialize_by (Rails)?

有没有办法重写下面的流程,目前使用find_or_initialize_by,使用joins方法?对于上下文-我有users(员工)在系统中记录他们的attendances(user有很多attendances,考勤记录属于用户)。Attendance.find_or_initialize_by(user:User.find_by(name:'Bob'),date:Time.zone.today).update(...)#Updatesomecolumnsafterthis我正在尝试使用.joins重写它,如下所示:Attendance.joins(:user).where(users

ruby-on-rails - 从 Rails 4.1.4 更新到 4.2.0 后,AR CollectionProxy 上的 "first!"引发 "undefined method [] for nil"

我开始从Rails4.1.4升级到Rails4.2.0。好像是第一!不再支持某些事件记录关联。first!(在ActiveRecord::Associations::CollectionProxy上)发生了什么导致它现在失败?如何修复该行为,使其像在4.1.4中一样工作?rails4.1:(byebug)user.organization.registration_codes#]>(byebug)user.organization.registration_codes.first!#rails4.2:(byebug)user.organization.registration_code

ruby - Chef : Can I share common per-environment run list items?

我在Chef中使用环境,我想使用每个环境的运行列表。问题是我不想重复自己(就像我现在做的那样)。示例:{"name":"myapp","default_attributes":{},"json_class":"Chef::Role","env_run_lists":{"production":[#Haslesspackagesbecauseservicesarespreadacrossspecializednodes"role[base]","recipe[mysql::client]","recipe[myapp]"],"staging":[#Haslesspackagesbecau

ruby-on-rails - Ruby on Rails2.3.8 : Unit Testing: Rails/Ruby has setup to run before each test. 在所有测试之前运行的方法怎么样?

我想在每次运行测试时初始化数据库一次,而不是每次测试。我知道Rspec有before(:all),但我无法让它工作。我想知道Rails是否有类似的东西。 最佳答案 首先:在Test::Unit中曾经有一个before(:all)等价物,但它被删除了(不知道为什么)。其次:有很好的理由不做你想做的事——测试应该相互独立运行,而不是依赖于数据库中的状态。这样您就可以保证它完全测试您期望它测试的内容。如果您有一个更改数据库状态的测试,并且您移动它并且它在另一个期望它是另一种状态的测试之后运行-您会遇到问题。因此,所有测试必须是独立的。因此

ruby - rvm 安装 ruby​​-1.9.3-p286 : Error running 'make -j 9' (OSX: Mountain Lion)

运行rvminstallruby​​-1.9.3-p286给我这个错误:Errorrunning'make-j9',pleaseread/Users/epeterson/.rvm/log/ruby-1.9.3-p286/make.logTherehasbeenanerrorwhilerunningmake.Haltingtheinstallation. 最佳答案 我花了很长时间才找到它。正在尝试不同版本的make、gcc等事实证明,rvm_make_flags环境变量的格式已从字符串更改为数组,并且没有很好地传达或记录。这可能适用于

ruby - rake/Rspec : How to suppress/quiet/silent the first output line showing the command with --pattern ?

问题:如果我运行ServerSpec(基于RSpec)到Rake使用以下命令之一:rakerakespecrakespec:allrakespec:bundleexecrake...Rake将它执行的命令打印到stdout在serverspec输出之前:/usr/bin/ruby1.9.1-I/var/lib/gems/1.9.1/gems/rspec-core-3.1.6/lib:/var/lib/gems/1.9.1/gems/rspec-support-3.1.2/lib/var/lib/gems/1.9.1/gems/rspec-core-3.1.6/exe/rspec--pa

ruby-on-rails - rails 3.1 : how to run an initializer only for the web app (rails server/unicorn/etc)

我的网络应用需要加密其session数据。我设置的是:config/initializers/encryptor.rb:require'openssl'require'myapp/encryptor'MyApp::Encryptor.config[:random_key]=OpenSSL::Random.random_bytes(128)Session.delete_allapp/models/session.rb:require'attr_encrypted'classSessionproc{MyApp::Encryptor.config[:random_key]},:marshal