草庐IT

touch-up-inside

全部标签

ruby 代码 : why put colon in front of variable name (inside initialize method)

我遇到了一些Ruby代码,我试图理解为什么变量在initialize方法声明中的名称末尾有冒号。冒号有什么原因吗?attr_reader:var1,:var2definitialize(var1:,var2:)@var1=var1@var2=var2end 最佳答案 那些是关键字参数。您可以按名称而非位置使用它们。例如ThatClass.new(var1:42,var2:"foo")或ThatClass.new(var2:"foo",var1:42)Anarticleaboutkeywordargumentsbythoughtbot

ruby - 混帐 & ruby : How can I unset the GIT_DIR variable from inside a ruby script?

我编写了一个非常简单的“部署”脚本,作为我的裸git存储库中的post-updateHook运行。变量如下livedomain=~/mydomain.comstagingdomain=~/stage.mydomain.comgitrepolocation=~/git.mydomain.com/thisrepo.git(bare)core=~/git.mydomain.com/thisrepo.gitcore==addedremoteintoeachlive&stagegitslive和stage都初始化了gitrepos(非裸),我已经将我的裸仓库作为远程添加到它们中的每一个(名为co

ruby-on-rails - Rails 2.3.5 : How does one access code inside of lib/directory/file. rb?

我创建了一个文件,这样我就可以在lib/foo/bar_woo.rb中的许多模型之间共享一个方法。在bar_woo.rb中,我定义了以下内容:moduleBarWoodefhelloputs"hello"endend然后在我的模型中我正在做类似的事情:defMyModel解释器提示它期望bar_woo.rb定义Foo::BarWoo。《使用Rails进行敏捷Web开发》一书指出,如果文件包含类或模块,并且文件使用类或模块名称的小写形式命名,那么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 - Rails 设计 : "You need to sign in or sign up before continuing" instead of "You will receive an email with instructions.."

我已经安装了DeviseonRails4.2.0,一切似乎都在工作,我使用了以下指南:http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/我的设计模块是:devise:database_authenticatable,:registerable,:confirmable,:recoverable,:rememberable,:trackable,:validatable,:omniauthable唯一的问题是,如果我尝试通过转到注册页面创建一个新帐户,然后在输入我的电子邮

ruby-on-rails - Rails add_index 算法 : :concurrently still causes database lock up during migration

为了防止在迁移到生产站点期间出现数据库事务错误,我们遵循了https://github.com/LendingHome/zero_downtime_migrations中列出的建议。(具体由https://robots.thoughtbot.com/how-to-create-postgres-indexes-concurrently-in概述),但在特别大的表上创建索引期间,即使是索引创建的“并发”方法也会锁定表并导致该表上的任何ActiveRecord创建或更新导致各自的事务失败有PG::InFailedSqlTransaction异常。下面是我们运行Rails4.2(使用Acti

ruby-on-rails - 仅当满足某些条件时,如何将 "touch"关联为 `belongs_to` 关联的父模型?

我正在使用Rails3.1.0,并且我想仅在满足某些条件时“触摸”belongs_to关联的父模型。比如此时我有:belongs_to:article,:touch=>true只有当它是“公共(public)的”时,我才会“接触”父模型。也就是说,Article类有一个名为access的属性(@article.access=>public或private),我想在“触摸”之前检查这个值:如果这个值不是public,那么“触摸”它!是否可以在belongs_to关联声明中“直接”进行?如果是,怎么做? 最佳答案 您可以按照您所说的尝试

ruby - 如何将 Ruby 哈希 "up"中的属性移动一级

x={:name=>"John",:data=>{:physical=>{:age=>25,:weight=>150}}}我希望将数据的子属性向上移动一个级别(但不一定只是简单地展平所有属性)。在这种情况下,我基本上想将:physical属性“向上”移动一个级别。我正在尝试这个y=x[:data']y.each{|key|x[key]=y[key]}但是我得到...x=x.except(:data)=>{:name=>"John",[:physical,{:age=>25,:weight=>150}]=>nil}我在找...=>{:name=>"John",:physical=>{:a

ruby-on-rails - 跳过 :touch associations when saving an ActiveRecord object

有没有办法在保存时跳过更新与:touch关联的关联?设置:classSchool我希望能够在跳过触摸的地方执行如下操作。@school=School.create@student=Student.create(school_id:@school.id)@student.name="Trevor"@student.save#CanIdothiswithouttouchingthe@schoolrecord?你能做到吗?像@student.save(skip_touch:true)这样的东西会很棒,但我还没有找到类似的东西。我不想使用像update_column这样的东西,因为我不想跳过A

ruby-on-rails - rails/Prawn : how do I use rails helpers inside a Prawn class?

我正在尝试在prawn类中使用rails3.2助手,但rails抛出:undefinedmethod`number_with_precision'for#Prawn类classQuotePdfControllerdefshow@quote=current_user.company.quotes.where(:id=>params[:id]).firsthead:unauthorizedandreturnunless@quoterespond_with@quote,:layout=>!params[:_pjax]do|format|format.pdfdosend_dataQuotePd