草庐IT

collection_name

全部标签

ruby-on-rails - Rails 4 + Devise : Invalid route name, 已在使用中

我正在按照此操作方法在成功注册后修改确认页面。https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-(registration)我按照它所说的做了所有事情,但我得到了这个错误:in`add_route':Invalidroutename,alreadyinuse:'new_user_session'(ArgumentError)Youmayhavedefinedtworouteswiththesamenameusingthe`:as`o

关于Document mapping type name can‘t start with ‘_‘, found: [_update]

在修改elasticsearch时,用_update进行局部修改,修改失败,报错{    "error": {        "root_cause": [            {                "type": "invalid_type_name_exception",                "reason": "Document mapping type name can't start with '_', found: [_update]"            }        ],        "type": "invalid_type_name_exce

ruby - 冒号(:) appears as forward slash (/) when creating file name

我正在使用日期和时间来标记我正在创建的新文件,但是当我查看该文件时,冒号是一个正斜杠。我正在使用10.7+在Mac上开发这是我使用的代码:File.open("#{time.hour}:00,#{time.month}-#{time.day}-#{time.year}","a")do|mFile|mFile.syswrite("#{pKey}-#{tKey}:\n")mFile.syswrite("Itemsclosed:#{itemsClosed}|Totalitems:#{totalItems}|Percentclosed:%#{pClosed}\n")mFile.syswrite

ruby-on-rails - rails : Testing named scopes with RSpec

我是测试Rails网络应用程序和RSpec的新手。我使用遗留代码并需要添加测试。那么使用RSpec测试查找器和命名范围的最佳方法是什么?我在Google中找到了一些方法,但它们并不理想。例如:http://paulsturgess.co.uk/articles/show/93-using-rspec-to-test-a-named_scope-in-ruby-on-railsit"excludesusersthatarenotactive"do@user=Factory(:user,:active=>false)User.active.should_notinclude(@user)e

ruby-on-rails - rails collection_select 与选择

collection_select和selectRails助手:我应该使用哪一个?我看不出这两种方式有什么不同。两个助手都获取一个集合并在select标签内生成options标签。是否存在collection_select优于select的场景?或者我在这里缺少什么? 最佳答案 collection_select旨在在项目列表是ActiveRecord对象数组时使用。collection_select构建在select之上,因此当您需要显示对象集合而不是字符串数组时,它是一种方便的方法。collection_select(:post

ruby-on-rails - ruby rails : How do you explicitly define plural names and singular names in Rails?

例如,我使用“Bonus”作为我的模型,所以我希望“bonuses”是复数形式而“bonus”是单数形式。但是,在Ruby中,这会导致:"bonus".pluralize#bonus"bonuses".singularize#bonuse因此,例如,当我执行“has_many:bonuses”时,它不会使用Bonus.rb模型(因为Ruby需要Bonuse.rb模型)。有没有一种方法可以在RubyonRails中以某种方式更正这一点,使“bonuses”充当模型bonus.rb的复数形式? 最佳答案 在config/initiali

ruby-on-rails - Rails : named_scope, lambda 和 block

我认为下面两个是等价的:named_scope:admin,lambda{|company_id|{:conditions=>['company_id=?',company_id]}}named_scope:admin,lambdado|company_id|{:conditions=>['company_id=?',company_id]}end但Ruby正在提示:ArgumentError:triedtocreateProcobjectwithoutablock有什么想法吗? 最佳答案 这是一个解析器问题。试试这个named_s

ruby - 跳过 Enumerable 中的迭代#collect

(1..4).collectdo|x|nextifx==3x+1end#=>[2,3,nil,5]#desired=>[2,3,5]如果满足next的条件,collect会将nil放入数组中,而我想要做的是将没有元素。这是否可以不调用delete_if{|x|x==nil}在返回的数组上?我的代码摘录非常抽象,因此正在寻找问题的通用解决方案。 最佳答案 有方法Enumerable#reject这只是为了:(1..4).reject{|x|x==3}.collect{|x|x+1}直接使用一种方法的输出作为另一种方法的输入的做法称为方

ruby - map、each 和 collect 之间有什么区别?

这个问题在这里已经有了答案:what'sdifferentbetweeneachandcollectmethodinRuby[duplicate](7个答案)关闭8年前。在Ruby中,each、map、collect的功能有区别吗?

ruby - Ruby 中的每个方法和 collect 方法有什么不同

这个问题在这里已经有了答案:Array#eachvs.Array#map(7个答案)关闭6年前。从这段代码中我不知道这两种方法之间的区别,collect和each。a=["L","Z","J"].collect{|x|putsx.succ}#=>MAAKprinta.class#=>Arrayb=["L","Z","J"].each{|x|putsx.succ}#=>MAAKprintb.class#=>Array