草庐IT

Collection-hooks

全部标签

ruby - Datamapper 的钩子(Hook)不起作用

无法理解为什么Hook不起作用。我有以下模型:classDirItemincludeDataMapper::Resource#property,property:id,Serialproperty:dir_cat_id,Integer,:required=>trueproperty:title,String,:required=>trueproperty:price,Integer,:default=>0belongs_to:dir_cathasn,:dir_photoshasn,:dir_field_valuesbefore:destroydologger.debug"=======

ruby-on-rails - 带有 :onchange and a :with 的 rails 2.1.2 collection_select

经过大量的搜索和阅读,我得到了一个看起来像这样的collection_select"this.value"},{:onchange=>remote_function(:url=>{:action=>"updatelevel",:controller=>"user",:id=>user.id})}%>但是它没有将选定的值传递给我的Controller,我唯一得到的就是一个nil。我搞砸了where:with应该是的不同组合并尝试了测试字符串,但它似乎从来没有做任何事情。我错过了什么愚蠢的东西吗?是否有我应该查看的“决定性”示例?Rails似乎变化如此之快,以至于很难知道论坛帖子谈论的是哪

ruby - 如何修补 ruby​​ 中的继承钩子(Hook)?

只是一个简单的例子。classBasedefself.inherited(child)p'Base.inherited'endendclassUser这产生了我"Base.inherited""User"这工作正常,但我如何修补Base类的inherited钩子(Hook)?假设我希望我的结果是"Base.inherited""Somethinginherited""User"并且仍然让我的User类继承Base。任何想法,解决方法?谢谢!更新问题更具体。我需要在User类继承Base而不修改User类的时候准确地运行一些代码。假设我有一个Base类,它定义了inherited方法。一

ruby-on-rails - 在 before_save Hook 中更改 ActiveRecord 属性值

我需要修复ActiveRecord属性的编码,并决定在before_saveHook中进行。在这一点上,我注意到了一个意想不到的功能。当我想更改属性的值时,简单地使用attribute_name=XY并没有像我预期的那样工作。而不是我需要使用self[:attribute_name]=XY。到目前为止还没有识别出这种行为,我使用了AR.attribute_name=XY。这是什么原因?这种行为与钩子(Hook)或其他东西有关吗?感谢您的解释。 最佳答案 这实际上是Ruby的“特性”:defvalue=(x)pxenddefrunva

ruby-on-rails - 我可以使用 github-services hook 将我的提要发布到其他服务吗?

Github已经开发了github-serviceshook来将提交推送到其他服务,如bugzilla、campfire、basecamp..是否可以使用相同的github-servicesHook将我的应用程序数据推送到其他服务?如果是,我该如何整合github-services到我的Rails应用程序。有什么帮助吗?有什么建议吗?更新我可以将github-serviceshook源代码作为Sinatra应用程序集成到我的Rails应用程序中吗?我如何从我的应用程序触发器中调用其他服务(bugzilla、campfire、basecam、twitter)Hook?例如,当一个用户在其

ruby-on-rails - rails 4 collection_select 多个嵌套属性未正确保存

我是Rails的新手,我在使用collection_select保存连接表的嵌套属性时遇到了问题。我有模型post、tag和post_tagging。post_tagging是一个连接表。我想为每个帖子设置多个标签,所以我尝试通过collection_select使用多选,但是当我保存时,只有post_id被插入到数据库中。下面是我的代码和日志。后.rbclassPost标签.rbclassTagpost_tagging.rb(我在post_tagging模型中关闭了对tag_id和post_id的存在验证,这样我就可以获得POST的日志。)classPostTaggingposts_

ruby-on-rails - Rails 低级缓存 : Update cache when ActiveRecord object updated_at changes OR when a new object is added to collection

Rails附带片段缓存和低级缓存。片段缓存的工作原理非常清楚:Railswillwriteanewcacheentrywithauniquekey.Ifthevalueofupdated_athaschanged,anewkeywillbegenerated.ThenRailswillwriteanewcachetothatkey,andtheoldcachewrittentotheoldkeywillneverbeusedagain.Thisiscalledkey-basedexpiration.Cachefragmentswillalsobeexpiredwhentheviewfr

ruby - 在 RSpec 中,如何在访问主题的子上下文中添加一个 before 钩子(Hook)?

考虑以下几点:describeMyModeldocontext'updatesfields'dosubject{create(:my_model)}beforedosubject.savesubject.reloadendcontext'whenchangingfoo.bar'dobefore{subject.foo.bar=3}it{is_expected.tobe_multiple_bar}endcontext'whenchangingbaz.quux'dobefore{subject.baz.quux=3}it{is_expected.tobe_multiple_quux}end

ruby - 如何在之前访问标签过滤器(:suite)/before(:all) hook in RSpec?

我想访问命令行传递的标签过滤器命令行rspec--taguse_ffRSpec配置RSpec.configuredo|config|config.before:suite,type::featuredo#howdoIcheckifuse_fffilterwasspecifiedinthecommandline?iffilter[:use_ff]use_seleniumelseuse_poltergeistendendend在before(:suite)钩子(Hook)中,我想访问在配置的命令行中指定的标签过滤器。根据rspec-core代码库,包含标签过滤器存储在inclusion_f

ruby-on-rails - 如何在编辑表单中预填充 collection_check_boxes?

GitHub存储库:https://github.com/Yorkshireman/mywordlist我用谷歌搜索了这个。我确定有办法,可能需要在html选项哈希中添加一些代码,但我无法解决。有什么想法吗?当访问_edit_word_form.html.erb部分单词时,确实有一个或多个类别,类别复选框都未选中,要求用户再次选择它们,即使他们不想更改类别。:title和:description的文本字段是预先填充的(谢天谢地)。_edit_word_form.html.erb:0%>AND/OR...words/index.html.erb相关部分:words_controller.