草庐IT

config_local

全部标签

ruby-on-rails - 在config/database.yml文件中存储生产环境的DB密码是否可以

在“config/database.yml”文件中存储生产环境的DB密码是否可以?还是有更正确的方法(也许是环境变量)?提前致谢。 最佳答案 这不是个好主意!一个主要原因是config/database.yml文件可能会包含在某种源代码控制中,例如git存储库。即使该repo目前是私有(private)的,您也无法确定它将来是否会公开,然后您就会遇到问题!此外,如果任何人获得了对您的应用程序文件的读取权限或只是您应用程序源代码的副本,他们现在就拥有了您的数据库密码。一个典型的解决方案是像您建议的那样设置一个环境变量,然后在.yml文

ruby-on-rails - rails 5 : How do I reference I18n translations from another yaml config file?

我有一个配置文件:#config/meta.ymlbase_meta:title:'Top10Cats'它有一个对应的初始化器:#config/initializers/meta.rbMETA=YAML.load_file("#{Rails.root.to_s}/config/meta.yml")我可以像这样访问标题:META['base_meta']['title']#=>"Top10Cats"但是,我想国际化我的元数据。我相信这应该由现有的locales/yaml文件处理。如何引用现有翻译?#config/locales/en.ymlen:title:'Top10Cats'我试过使

ruby - config.ru if 生产语句

在我的config.ru中,我想设置一个代码块,该代码块将根据环境运行特定代码。我尝试了一些代码,但没有任何成功。有什么建议吗?ifENV['RAKE_ENV'].to_s.eql?('development')Bundler.require(:default,:development)end 最佳答案 我相信您想检查ENV['RACK_ENV']而不是ENV['RAKE_ENV']。 关于ruby-config.ruif生产语句,我们在StackOverflow上找到一个类似的问题:

ruby - Jekyll Liquid - 动态访问 _config.yml

为了使我的应用国际化,我需要能够动态访问YAML文件中的条目。最好用一个例子来解释:页面:---layout:defaulttitle:title_homepage---这将允许访问默认布局模板中的title_homepage变量:默认布局:page.title="title_homepage"现在通常我会像这样访问我的_config.yml文件:{{site.locales[site.default_locale].variable}}但是,现在要让它工作,我需要使用page.title的值访问_config.yml。这是行不通的:{{site.locales[site.defaul

Ruby 动态数组 : undefined local variable or method `s' for main:Object (NameError)

我对ruby​​还是个新手。由于某种原因没有看到我的数组。我在irb中测试了我的代码逻辑,它似乎工作正常,但是当我在if语句中使用它时,它因标题中的错误而中断。$s=[]i=0File.open("test.log").eachdo|l|ifl=~/(m.)/s一个例子test.log:aaaaaaaaaaaaaaaaaam1gggp1p2p3p4oooooooooooooom2p1p2p3p4p5ggggggggggggggm3p1kkkkkkkkkkkkm4m5llllllllllllll我怎样才能得到这样的数组?[[m1,p1,p2,p3,p4],[m2,p1,p2,p3,p4,

ruby - Sinatra - 通过 config.ru 设置缓存控制 header

我目前正在Heroku的Cedar堆栈上运行一个Octopress(基于Jekyll)站点——代码位于此处:https://github.com/elithrar/octopress我想根据文件类型有选择地应用Cache-Controlheader:.html文件获取值public,max-age=3600.css|.js|.png|.ico(等)获得public,max-age=604800的值-或者,我想将此规则应用于/stylesheets'、'/javascripts'、'/imgs'目录提供的任何内容。同时使用了set:static_cache_control,[:publi

ruby - heroku 上的非 Rails 应用程序的 config.ru 中有什么内容?

我有一个使用resque的简单ruby​​(非rails)应用程序,如果没有heroku上的config.ru就无法启动。当我添加config.ru文件时,在本地运行rackup时出现以下错误:/usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:133:in`to_app':missingrunormapstatement(RuntimeError)from/Users/nickkarrasch/Dropbox/Coding/Ruby/smsnotifyv2/

ruby - 从 config.ru 设置 Sinatra 应用设置

当我使用Sinatra作为Rack中间件时,我可以在我的Rackup文件中这样做:useMyGloriousApp.newdo|le_app|le_app.settings.set:frobnicate,trueend当我需要中间件末尾的runblock时,我该如何完成相同的操作链?有点像runMyGloriousApp.newdo|le_app|le_app.settings.set:frobnicate,trueend 最佳答案 这是由创建block时do...end语法的优先级引起的。你的例子:runMyGloriousApp

ruby-on-rails - Rails local_assign 与局部变量

从Railsguide中学习,我不明白local_assign下面是如何工作的:Topassalocalvariabletoapartialinonlyspecificcasesusethelocal_assigns.index.html.erbshow.html.erb_articles.html.erbThiswayitispossibletousethepartialwithouttheneedtodeclarealllocalvariables.当它的名称为_articles时,showAction如何呈现部分,它只会显示indexAction?我也不明白您为什么要使用添加fu

ruby-on-rails - rails : Setting locale appropriately to IP address

我正在尝试使用request.location(geocodergem),将区域设置适本地设置为客户端IP地址。这是我得到的:app/controllers/application_controller.rbbefore_action:set_localeprivatedefset_locale#getlocationwithgeocoderlocation=request.location#setlocalethroughURLifparams.has_key?(:locale)I18n.locale=params[:locale]||I18n.default_locale#setl