草庐IT

customer_names

全部标签

关于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 - 事件管理员 : Customize only new form

我正在使用ActiveAdmin为某些模型提供管理员。我需要为其中一个提供自定义的新表单,但将编辑表单保留为ActiveAdmin提供的默认表单。这就是我所拥有的。它的工作原理是它为我提供了我想要的新表单,但编辑表单也在使用新表单,这不是我想要的:ActiveAdmin.registerDocumentdoform:partial=>'form'end我试过这个,但它给出了一个错误,“new”是一个未定义的方法:ActiveAdmin.registerDocumentdonewdoform:partial=>'form'endend 最佳答案

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 元编程 : dynamic instance variable names

假设我有以下哈希:{:foo=>'bar',:baz=>'qux'}我如何动态设置键和值以成为对象中的实例变量...classExampledefinitialize(hash)...magichappenshere...endend...这样我就可以在模型中得到以下内容...@foo='bar'@baz='qux'? 最佳答案 您要找的方法是instance_variable_set.所以:hash.each{|name,value|instance_variable_set(name,value)}或者,更简单地说,hash.e

ruby-on-rails - rails : Custom text for rails form_for label

我想在form_for中显示一个标签:这会生成标签“姓名”,但我希望它是“您的姓名”。我该如何更改它? 最佳答案 label帮助器的第二个参数将允许您设置自定义文本。使用RubyonRailsDocumentation查找辅助方法。 关于ruby-on-rails-rails:Customtextforrailsform_forlabel,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questio

ruby - map(& :name) mean in Ruby? 是什么意思

我在aRailsCast中找到了这段代码:deftag_names@tag_names||tags.map(&:name).join('')endmap(&:name)中的(&:name)是什么意思? 最佳答案 它是tags.map(&:name.to_proc).join('')的简写如果foo是一个带有to_proc方法的对象,那么你可以将它作为&foo传递给一个方法,它将调用>foo.to_proc并将其用作方法block。Symbol#to_proc方法最初由ActiveSupport添加,但已集成到Ruby1.8.7中。这

javascript - react : get custom checkbox's checked attribute

我想用复选框进行一些自定义,它看起来像这样:所以我将我的自定义复选框包装到React组件中:require('../../less/ck-checkbox.less');varReact=require('react');varCkCheckbox=React.createClass({propTypes:{name:React.PropTypes.string,text:React.PropTypes.string,defaultChecked:React.PropTypes.bool,onChange:React.PropTypes.func},getDefaultProps:fu