Tag: yaml

从Rails(表单)向Javascript发送数据

我在Rails中存储了一些数据,然后我从Javascript访问。 (我正在使用gon gem这样做)。 当我在控制器中对字符串值(对于gon)进行硬编码时,它工作正常,我可以从javascript访问这些数据: #set in rails, available in JS gon.stuff = { “1” => “one stuff\n print ‘hi’.. “, “2” => “two stuff\n print ‘by’ “} 但是,当我通过Rails表单提交数据(到Post的’stuff’列)时,它最终会“过度字符串化”,因此它在Javascript中显示为一个完整的字符串: post.stuff text_area: { “1” => “stuff about one\n more stuff.. “, “2” => “two stuff\n more stuff”} 在rails中设置数据: gon.stuff = @post.stuff JS数据最终为完整字符串: “{ “1” => “stuff about […]

bundle install导致“在此上下文中不允许映射值”错误

我有一个已经工作了一段时间的rails 4项目。 我试图安装taps但收到错误消息: $ gem install taps /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:370:in `parse’: (): mapping values are not allowed in this context at line 2 column 29 (Psych::SyntaxError) from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:370:in `parse_stream’ from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:318:in `parse’ from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:245:in `load’ from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/config_file.rb:333:in `load_file’ from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/config_file.rb:198:in `initialize’ from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/gem_runner.rb:74:in `new’ from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/gem_runner.rb:74:in `do_configuration’ from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/gem_runner.rb:39:in `run’ from /usr/local/rvm/rubies/ruby-2.2.1/bin/gem:21:in `’ 尝试运行gem list或bundle update时,我收到相同的错误消息。 我搜索了类似的问题 […]

Heroku删除我上传的文件,为什么?

如果我在Heroku上的应用程序中加载文件,一切正常,但当我再次尝试重新加载应用程序时,它会给我以下错误: 2013-01-25T08:48:31+00:00 app[web.1]: app/controllers/main_controller.rb:20:in `index’ 2013-01-25T08:48:31+00:00 app[web.1]: 2013-01-25T08:48:31+00:00 app[web.1]: 2013-01-25T08:48:31+00:00 app[web.1]: Errno::ENOENT (No such file or directory – /app/config/cases/casesID6.yml): 2013-01-25T08:48:31+00:00 app[web.1]: app/controllers/main_controller.rb:20:in `read’ 本地工作很精细! 主控制器: # importo yaml di configurazione require ‘yaml’ if Survey.exists?(1) @idOfSurvey = Survey.find {|s| s[‘active_state’] == true}[‘id’] nameOfSurvey = “casesID”+String(@idOfSurvey)+”.yml” @survey = YAML::load(ERB.new(IO.read(File.join(Rails.root, ‘config/cases’, nameOfSurvey))).result) else render :action => ‘noYaml’ and […]

haml,link_to helper和I18n在同一个句子中

这是我想要获得的标记: View more clinic information including physicians, locations, directions, documents, and more. 我正在使用haml,yaml和Rails(哦,我的!)。 为了通过本地化做到这一点,我必须有这个yaml: en: view_more: View more link: clinic information details: including physicians, locations, directions, documents, and more. 把我的haml放在3行上,如: %p = I18n.t(‘view_more’) = link_to I18n.t(‘link’), clinic = I18n.t(‘details’) 似乎必须有一个更好的方法。 第一个问题是,这对于具有不同语法的语言不起作用,其中由于语法词序,链接可能出现在句子的末尾。 有没有办法将链接作为参数传递? 但是我必须在yaml中插入它,并且可能在那里放置标记? 这似乎也不是很好。 有一种优雅的方式可以做到这一点,我错过了吗?

在Rails中重新生成夹具测试文件

如何重新生成所有YML夹具文件? 我不小心删了它们。

Rails活动记录查询,序列化数组

假设我有用于以String数据类型存储pet数组的Users数据 [ #, #, #, # ] 我可以让所有有猫的用户? 也许像User.find_all_by…或User.where(….)或任何作为关系返回的东西? 所以我可以订购有效的记录查询。 我知道我可以让所有有猫的用户 User.all.select{|s| YAML.load(s.pets).include?’cat’} ,但它转换为无法与活动记录查询一起订购的数组。 thx求助。

rails,yml和multiline

我不能为我的生活从我的语言环境文件中获取多行yaml工作。 我尝试过多种解决方案的各种组合但没有成功。 我试过key: | , key: > ,带双引号,带单引号,带\ n,下一行的值,缩进,可能还有其他一些。 在我看来,我只是使用t(‘key’) 我在这里撕扯我的头发。 任何其他建议或可能的原因多线值的默认yaml规范不起作用?

rails database.yml不接受ERB

在我的database.yml中,我有: staging: adapter: encoding: database: host: port: pool: username: password: 但是,在实际启动puma时它不会读取ERB部分: /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require’: Could not load ‘active_record/connection_adapters/_adapter’. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than ‘mysql’, ‘mysql2’, ‘postgresql’ or ‘sqlite3’ add the necessary adapter gem to the Gemfile. (LoadError) 这没有任何意义,因为在Rails代码中加载数据库配置: def database_configuration yaml = Pathname.new(paths[“config/database”].existent.first || “”) […]

Rails3 – 如何在应用程序中获取aws-s3的yml配置数据?

具体来说,我有一个文件config / amazon_s3.yml,aws-s3 gem使用它来设置一些s3配置设置,比如密钥等。我还将一些这样的数据写入ENV中的var中,在初始化程序的不同文件中所以我可以通过调用paperclip使用的“has_attached_file”方法来引用它们。 在初始化器中获取文件以从s3配置yml中读取它们,或者为gem使用的类的一些配置设置更聪明,例如AWS::S3::Base.connection.secret_access_key (这不是’工作)。 有任何想法吗?

使用可选参数在.yml中进行翻译

我想用可选参数进行翻译my_translation 。 例如: > I18n.t(‘my_translation’) => “This is my translation” > I18n.t(‘my_translation’, parameter: 1) => “This is my translation with an optional parameter which value is 1” 这可能吗?