草庐IT

how-to-fix-crawl-errors-in-google

全部标签

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 线程崩溃,但处理了 Timeout::Error

任何人都可以解释为什么当对方法的调用看起来像这样时我可能会看到这个堆栈(由HTTParty::post请求引起):beginresponse=HTTParty::post(url,options)rescuelogger.warn("Couldnotpostto#{url}")rescueTimeout::Errorlogger.warn("Couldnotpostto#{url}:timeout")end堆栈:/usr/local/lib/ruby/1.8/timeout.rb:64:in`timeout'/usr/local/lib/ruby/1.8/net/protocol.rb

ruby-on-rails - rails : Pass Parameters to New Controller during 'redirect_to'

我正在使用RyanBates的RailsCastonWickedWizardForms创建一个多步骤表单。我没有定义current_user方法(不使用身份验证gem)-因此,我试图在redirect_to期间传递user.id参数-不幸的是,我似乎无法让它工作。任何帮助表示赞赏!我的用户Controller创建方法defcreate@user=User.new(params[:user])respond_todo|format|if@user.saveformat.html{redirect_tocontroller:'user_steps',id:'user.id'}#format

ruby-on-rails - rails 教程 : Putting flash messages in partial yields error "undefined method ` each' for nil:NilClass"?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:FlashMessagesinPartials(Rails3)我正在做MichaelHartl的Railstutorial和listing7.26将flash消息添加到应用程序布局:...">...这很好用。但是,我试图通过在我的部分文件夹中创建一个_flash.html.erb来清理这段代码...">-->...并且比使用......在我的应用程序布局中,我的所有Rspec测试开始失败,每个测试都显示以下消息:Failure/Error:before{visitsignup_path}ActionView:

ruby - 是否有与 'new' 哈希语法等效的 Ruby Hash#to_s?

Hash#to_s(inspect的别名)始终以1.8哈希样式输出数据:{key:"value"}.to_s=>"{:key=>\"value\"}"是否有任何核心方法将其序列化为1.9哈希样式?{key:"value"}.to_s=>"{key:\"value\"}"我在已知数据上使用它进行代码重构;由于Ruby倾向于实现所有内容,我希望我只是找错了地方。当然,你可以用丑陋的方式破解它"{"+my_hash.to_a.map{|pair|pair[0].to_s+":"+pair[1].inspect}*",\n")+"}"但我希望有一个经过单元测试且完全正确的核心方法。

ruby-on-rails - Thinking sphinx - 带条件连接的索引 (has_and_belongs_to_many)

我有模型Service,它具有按服务类型ID过滤服务的范围:classServiceids{joins(:service_types).where('service_types_services.service_type_idin(?)',ids)}endclassServiceType所以,当我运行scope时,我得到这样的结果:Service.by_service_types([54])ServiceLoad(0.8ms)SELECT"services".*FROM"services"INNERJOIN"service_types_services"ON"service_types

ruby - Rails+ActiveAdmin - 使用 ransacker 过滤会抛出错误 PG::SyntaxError: ERROR: syntax error at or near ","

我在RubyonRails4.1.4上有一个项目,使用来自git://github.com/activeadmin/activeadmin的activeadmin1.0.0.pre,pg0.17.1,PostgreSQL9.3在项目中我有这些模型:类用户has_one:账户类账户属于:用户有很多:project_accountshas_many:项目,:through=>:project_accounts类项目#该项目有一个bool属性'archive'has_many:project_accounts类ProjectAccount属于:帐户属于:项目我有一个任务是在索引页面上实现一个

ruby 雾 gem : how to create sub-directories?

我有connection=Fog::Storage.new(fog_config)bucket=connection.directories.get(bucket_name)有没有办法(已记录、未记录、变通)让我在此存储桶内创建目录?像这样的东西:sub_dir_for_user_1=bucket.create_sub_dir('/user_1_files')sub_dir_for_user_2=bucket.create_sub_dir('/user_2_files') 最佳答案 在S3中,带有尾部斜杠的零字节文件将创建一个伪目录

ruby-on-rails - rspec rails 测试 : how can I force ActiveJob job's to run inline for certain tests?

我希望我的后台作业能够内联运行某些标记测试。我可以通过用perform_enqueueddo包装测试来做到这一点,但我希望能够用元数据标记它们,如果可能的话,它会自动发生。我试过以下方法:it"doeseverythinginthejobtoo",perform_enqueued:truedoendconfig.around(:each)do|example|ifexample.metadata[:perform_enqueued]perform_enqueued_jobsdoexample.runendendend但它会导致错误:undefinedmethod`perform_enq

ruby-on-rails - Rails 5 升级 :/actionpack-5. 0.0/lib/action_controller/test_case.rb:49:in `initialize':参数数量错误(0 代表 2)(ArgumentError)

我最近正在进行Rails5升级,当我尝试启动Rails控制台时遇到了这个错误:/actionpack-5.0.0/lib/action_controller/test_case.rb:49:ininitialize':wrongnumberofarguments(0for2)(ArgumentError)当前bundleupdaterails已经完成了gem依赖项的解决,足以更新到5.0.0,rspec正在运行(尽管我正在修复很多中断)。我也可以运行railss没有错误。这里是代码中断行:https://github.com/rails/rails/blob/master/action