草庐IT

hour_from

全部标签

ruby-on-rails - Rails 3 I18 : translation missing: da. datetime.distance_in_words.about_x_hours

我看到这个错误:translationmissing:da.datetime.distance_in_words.about_x_hours我的语言环境文件:http://pastie.org/2944890我的看法:我已将其添加到我的application.rb中:config.i18n.load_path+=Dir[Rails.root.join('my','locales','*.{rb,yml}').to_s]config.i18n.default_locale=:da如果我删除I18配置,帮助程序会处理英语。更新:我在config/enviorments/devolpment

ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative'

我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

ruby-on-rails - rails : save file from URL and save it to Amazon S3

从给定URL下载文件并立即将其上传到AmazonS3的更直接的方法是什么(+将有关文件的一些信息保存到数据库中,例如名称、大小等)?现在,我既不使用Paperclip,也不使用Carrierwave。谢谢 最佳答案 简单明了:require'open-uri'require's3'amazon=S3::Service.new(access_key_id:'KEY',secret_access_key:'KEY')bucket=amazon.buckets.find('image_storage')url='http://www.ex

ruby-on-rails - Rails 6 中的 protect_from_forgery?

protect_from_forgery默认Rails6应用程序不包含在我的应用程序Controller中,但是有嵌入式ruby​​在主应用程序布局中。这是否意味着protect_from_forgery方法已经被抽象并且在应用程序Controller中不再明确需要?我买了实用程序员的Rails6一书,我唯一能找到的是“csrf_meta_tags()方法设置了防止跨站点请求伪造攻击所需的所有幕后数据”。 最佳答案 对于rails5.2和更高版本,默认情况下在ActionController::Base上启用。查看此提交:https

ruby - Chef : Read variable from file and use it in one converge

我有以下代码,它下载一个文件,然后将文件的内容读入一个变量。使用该变量,它执行一个命令。这个配方不会收敛,因为/root/foo在编译阶段不存在。我可以通过多个聚合和一个来解决这个问题ifFile.exist但我想用一个收敛来完成它。关于如何做到这一点有什么想法吗?execute'download_joiner'docommand"awss3cps3://bucket/foo/root/foo"not_if{::File.exist?('/root/foo')}endpassword=::File.read('/root/foo').chompexecute'join_domain'd

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 - 覆盖 Controller 中的 protect_from_forgery 策略

我想使用两种不同的protect_from_forgery策略构建一个Rails应用程序:一种用于Web应用程序,一种用于API。在我的应用程序Controller中,我有这行代码:protect_from_forgerywith::exception为了防止CSRF攻击,它工作得很好。在我的API命名空间中,我创建了一个继承self的应用程序Controller的api_controller,它是API命名空间中所有其他Controller的父类,我将上面的代码更改为:protect_from_forgery:null_session.遗憾的是,我在尝试发出POST请求时遇到错误:“

ruby - 如何强制 Rack :session + sinatra to read "rack.session" from params instead of cookies

我正在处理oauth1.0(twitter和flickr)。网站工作在80端口,oauth服务器工作在8080端口算法:向oauth服务器发送ajax请求以检查用户是否有有效的access_token如果用户没有access_token或access_token已过期,则打开授权窗口在oauth服务器的用户session中保存access_token发送分享数据到oauth服务器它使用sinatra+rack:session+rack::session::sequel+sqlite来存储session。它在每个响应中发送Set-Cookie:rack.session=id我正在使用2种

ruby-on-rails - 在 Rails 中获取 "Incomplete response received from application"

有人可以帮忙吗?我的堆栈是带有nginx/passenger和ruby​​2.2.2的ubuntu-server14.04。我无法使我的项目投入生产。在开发中一切运行正常。secret.ymlproduction:secret_key_base:secret_token:服务器server{listen80;server_namelogvs.local;passenger_enabledon;passenger_app_envdevelopment;root/var/www/logvs/public;}错误日志App2532stderr:[2015-06-0722:56:01.4724

ruby - 为什么在:save callback hook not getting called from FactoryGirl. create()之前?

这个简单的示例使用DataMapper的before:save回调(又名Hook)来增加callback_count。callback_count初始化为0,回调应该设置为1。当通过以下方式创建TestObject时调用此回调:TestObject.create()但是当FactoryGirl通过以下方式创建时会跳过回调:FactoryGirl.create(:test_object)知道为什么吗?[注意:我正在运行ruby​​1.9.3,factory_girl4.2.0,data_mapper1.2.0]详细信息如下...DataMapper模型#file:models/test_