草庐IT

your_collection

全部标签

ruby-on-rails - rails/事件记录 : save changes to a model's associated collections

我是否必须保存对模型集合中单个项目的修改,或者是否有一种方法可以在我保存模型时调用以保存它们。#save似乎没有这样做。例如:irb>rental=#...#=>#irb>rental.dvd#=>#,sale_price:#>irb>rental.dvd.copies+=1#=>21irb>rental.save#=>trueirb>rental.dvd#=>#,sale_price:#>irb>Dvd.find_by_title('TheWomenofSummer')#=>#,sale_price:#>在上面的例子中,租赁的DVD副本似乎没有更新数据库中的副本(注意不同的副本数)。

ruby - 返回 Enumerable 的 Ruby Enumerable.collect 的等价物?

在这段代码中,我创建了一个字符串数组“1”到“10000”:array_of_strings=(1..10000).collect{|i|String(i)}RubyCoreAPI是否提供了一种获取可枚举对象的方法,让我可以枚举同一个列表,按需生成字符串值,而不是生成字符串数组?这是一个进一步的示例,希望能阐明我正在尝试做的事情:deffind_me_an_awesome_usernameawesome_names=(1..1000000).xform{|i|"hacker_"+String(i)}awesome_names.find{|n|notstackoverflow.usere

ruby - 如何解析 "Your bundle only supports platforms ["x86-mingw3 2"] but your local platforms are ["ruby​​", "x86_64-linux"]"

我正在Windows机器上构建一个Rails站点,但是当我检查我的Gemfile.lock时,我在我的Travis构建中遇到以下错误:Yourbundleonlysupportsplatforms["x86-mingw32"]butyourlocalplatformsare["ruby","x86_64-linux"],andthere'snocompatiblematchbetweenthosetwo列表这是完整的日志:https://travis-ci.org/bikebike/BikeBike/builds/222395810#L654我查看了我的Gemfile.lock并指出:

ruby-on-rails - Rails Impressionist Gem - WillPaginate::Collection 不令人印象深刻

有什么方法可以将印象派gem与分页一起使用?我尝试将印象派用于will_paginate集合,如下所示:posts=Post.all.paginate(:page=>params[:page])impressionist(posts)但是它引发了这个错误:WillPaginate::Collectionisnotimpressionable!有什么方法可以直接在View上使用印象派方法? 最佳答案 will_paginate生成的集合不易受影响意味着您正在阅读,它的类没有调用is_impressionable,正如您的模型应该调用的

ruby - 在 collection_select rails 中选择多个选项

我知道如何组合一个从模型中获取值的简单选择框"PleaseSelectaSector")%>我的问题是如何允许用户选择多个选项,然后将它们存储在模型中。我知道我需要使用:multiple=>true但不确定语法通常对于一个模型的多个条目,我会使用accepts_nested_attributes_for,但我认为我不需要对这个例子这样做是否正确?谢谢 最佳答案 经过一些尝试和错误后确定"PleaseSelectaSector"},{:multiple=>true})%>让我选择多个选项

ruby-on-rails - f.collection_select 不显示选择的值

在google上有很多关于此搜索的结果,甚至有人在SO上询问过-但到目前为止讨论的解决方案对我没有帮助。问题是:我有一个form_for@company|f|并且我正在为company_status_id使用f.collection_select-但是当加载表单时,如果已设置,我希望选择实际的公司状态。通过我知道的调试器,它已被设置,但我在那里显示了一个默认值。这是代码:=puts@company.company_status_id=f.collection_select:company_status_id,ListCache.company_statuses,:id,:name,{:

ruby-on-rails - 从 Ruby on Rails 中的 collection.map 中排除选项?

我有这样一行:{:value=>(policy_address.state.namerescuenil)},:required=>true,:collection=>states.map{|s|[s.name,s.id]},:include_blank=>'Pleaseselect'%>我想从states.map集合中排除一个值。我认为这行得通,但行不通:{:value=>(policy_address.state.namerescuenil)},:required=>true,:collection=>states.map{|s|[s.name,s.id]unlesss.name==

ruby-on-rails - 将类添加到 collection_select

我看过HowdoIsettheHTMLoptionsforcollection_selectinRails?我确信我遗漏了一些明显的东西,但我无法让它发挥作用。我的选择目前看起来像:'Broadcaston...'%>我已经尝试包括:class=>'prevent_collapse',它什么都不做,以及{:class=>'prevent_collapse'},它给出我出错了。如果有人能指出如何做到这一点,我将不胜感激! 最佳答案 collection_select(object,method,collection,value_met

ruby-on-rails - rails : Your user account isn't allowed to install to the system RubyGems

我正在运行命令bundleinstall在项目文件夹中。在某些项目文件夹中,它会产生错误,而在其他项目文件夹中,它不会产生错误。错误是:Youruseraccountisn'tallowedtoinstalltothesystemRubyGems我知道这可以通过遵循推荐的建议来解决:bundleinstall--pathvendor/bundle我的问题是为什么行为不一致? 最佳答案 在我的例子中,我按照错误消息的建议解决了问题:Youruseraccountisn'tallowedtoinstalltothesystemRubyG

ruby 和 "You must recompile Ruby with OpenSSL support or change the sources in your Gemfile"

我使用rvm将我的ruby​​升级到1.9.3-p392,还添加了2.0.0,每当我尝试使用这个版本时,当我运行我的bundle命令时,我都会收到这个错误。CouldnotloadOpenSSL.YoumustrecompileRubywithOpenSSLsupportorchangethesourcesinyourGemfilefrom'https'to'http'.InstructionsforcompilingwithOpenSSLusingRVMareavailableatrvm.io/packages/openssl.我已经按照几个不同的说明来解决这个问题。我尝试删除版本并