草庐IT

console-output

全部标签

ruby-on-rails - 更好的替代方法 try( :output). try( :data). try( :name)?

“输出”是一个序列化的OpenStruct。定义标题try(:output).try(:data).try(:title)结束什么会更好?:) 最佳答案 或者只是这样:deftitleoutput.data.titlerescuenilend 关于ruby-on-rails-更好的替代方法try(:output).try(:data).try(:name)?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.c

ruby - 从 Ruby : capturing the output while displaying the output? 运行 shell 命令

我有一个问题。我想从另一个ruby​​脚本运行一个ruby​​脚本并捕获它的输出信息,同时让它也输出到屏幕。亚军#!/usr/bin/envrubyprint"Enteryourpassword:"password=gets.chompputs"Hereisyourpassword:#{password}"我运行的脚本文件:开始.rboutput=`runner`putsoutput.match(/Hereisyour(password:.*)/).captures[0].to_s正如您在此处看到的那样,存在问题。在start.rb的第一行,屏幕是空的。我在运行程序中看不到“输入您的密

sql - 在 Rails Console for PostgreSQL 的表中显示数据

我找到了这样的东西:Rails:Howtolistdatabasetables/objectsusingtheRailsconsole?这一行没问题:ActiveRecord::Base.connection.tables并返回所有表但是ActiveRecord::Base.connection.table_structure("users")产生错误:ActiveRecord::Base.connection.table_structure("projects")我认为table_structure不是Postgres方法。如何列出Postgres数据库的Rails控制台中表中的所有

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 - 奇数 rake db :migrate output

为什么rakedb:migrate运行Executedb:schema:dump我的输出全都搞砸了(显示SQL)。看起来像这样:ActiveRecord::SchemaMigrationLoad(0.5ms)SELECT"schema_migrations".*FROM"schema_migrations"(3.7ms)SELECTt2.oid::regclass::textASto_table,a1.attnameAScolumn,a2.attnameASprimary_key,c.connameASname,c.confupdtypeASon_update,c.confdeltyp

Ruby minitest assert_output 语法

我是minitest的新手,也是ruby​​的新手,我真的厌倦了用谷歌搜索这个问题却没有结果。非常感谢您的帮助:rubyminitest中assert_output的确切语法是什么?我在github或其他地方找到的所有内容似乎都使用括号。然而,当我不使用带有assert_output的block时,我收到一条错误消息,这是有道理的,因为此方法的定义包含yield语句。但无论我怎样尝试,我都无法让它发挥作用。测试类.rbclassTestClassdefoutputputs'hey'endend测试测试.rbrequire'minitest/spec'require'minitest/a

ruby-on-rails - RubyOnRails : How do I use helper methods in Rails Console?

可能是我的设置有问题:irb(main):001:0>truncate("Onceuponatimeinaworldfarfaraway",:length=>17)NoMethodError:undefinedmethod`truncate'formain:Objectfrom(irb):1from/usr/lib64/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in`start'from/usr/lib64/ruby/gems/1.9.1/gems/railties-3.2.8/lib/ra

Ruby - 创建 gem : reload console with updated gem content

根据这个article,我们可以通过将这些行添加到我们的rakefile来测试我们的gem代码:​​task:consoledorequire'irb'require'irb/completion'require'my_gem'#Youknowwhattodo.ARGV.clearIRB.startend它工作得很好,只是每当对gem进行更改时,我都需要退出并重新运行rakeconsole以更新代码。作为创建/调试工具确实不方便...有没有一种方法可以编写一个自定义方法来充当Rails中很棒的reload!方法?bash脚本不会工作,因为第一个命令在Ruby控制台中,我宁愿有一个100

ruby-on-rails - rails console - 运行一段代码

我了解如何在Rails控制台中运行一段简单的代码。说Swimming::Student.create(:name="Jerry")我如何运行一大段代码(很多行)Swimming::Student.all.each{|student|student.attended=flasestudent.save} 最佳答案 如您所料,只需按回车键:$railscLoadingdevelopmentenvironment(Rails3.2.13)2.0.0p0:001>Student.all.eachdo|student|#enter2.0.0p

ruby-on-rails - rails 2 : test 'link_to' and other view helpers from the rails console?

在Rails2中,我经常使用控制台,并且想知道使用它测试View助手(例如“link_to”或“url_for”)的最佳方法是什么。执行此操作的最佳方法是什么? 最佳答案 您可以将您的includeActionView::Helpers::UrlHelper添加到~/.irbrc以在您启动控制台时自动加载它。 关于ruby-on-rails-rails2:test'link_to'andotherviewhelpersfromtherailsconsole?,我们在StackOverfl