草庐IT

all_name

全部标签

关于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-on-rails - 在 RSpec 中,在 :all block 之前使用 let 变量

我的大部分测试中都有以下代码:describe'index'let(:company){FactoryGirl.create(:company)}let(:user){FactoryGirl.create(:user,company:company)}beforedosign_inuservisitproducts_pathend...end但我收到以下警告:WARNING:letdeclaration'user'accessedina'before(:all)'我的问题是,这样做的正确方法是什么?我找不到关于警告本身的太多信息。谢谢!编辑:我的目标是使用user变量,这样我就可以将它

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 - "find_all"和 "select"是一回事吗?

这两个语句给我相同的结果:[1,2,3,4].find_all{|x|x.even?}[1,2,3,4].select{|x|x.even?}find_all只是一个别名吗?有理由使用一个而不是另一个吗? 最佳答案 #find_all和#select非常相似;差异非常微妙。在大多数情况下,它们是等价的。这取决于实现它的类。Enumerable#find_all和Enumerable#select在同一代码上运行。Array和Range也是如此,因为它们使用Enumerable实现。在Hash的情况下,#select被重新定义为返回一

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 : Postgres permission denied to create database on rake db:create:all

我正在尝试创建用于开发和测试的postgres数据库。我正在使用:OSX优胜美地Rails版本:4.2.0git版本:2.2.2psql版本:9.4.0ruby版本:2.1.0p0自制软件版本:0.9.5gem文件:gem'pg'数据库.yml:default:&defaultadapter:postgresqlencoding:unicodepool:5development:rakedb:create:all返回PG::InsufficientPrivilege:ERROR:permissiondeniedtocreatedatabase:CREATEDATABASE"myapp_

ruby-on-rails - 什么是 Post.all.map(& :id) mean?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whatdoesmap(&:name)meaninRuby?Post.all.map(&:id)会回来=>[1,2,3,4,5,6,7,................]map(&:id)是什么意思?特别是&。

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-on-rails - rails ActiveRecord : Find All Users Except Current User

我觉得这应该很简单,但是我的脑子短路了。如果我有一个代表当前用户的对象,并且想查询除当前用户之外的所有用户,考虑到当前用户有时可能为nil,我该怎么做?这就是我现在正在做的:defindex@users=User.all@users.deletecurrent_userend我不喜欢的是我正在对查询结果进行后处理。除了感觉有点不对之外,如果我将查询转换为使用will_paginate运行,我认为这不会很好地工作。关于如何通过查询执行此操作的任何建议?谢谢。 最佳答案 可以在Rails4及更高版本中执行以下操作:User.where.