草庐IT

ATTRIBUTES

全部标签

ruby-on-rails - rails : dynamic columns/attributes on models?

我有一个SaaS应用程序,帐户想要在用户模型上保存不同类型的信息。因此,例如,一个帐户可能想要保存年龄和生日,但在另一个帐户中,他们不会使用这些列,而是想要保存头发颜色和高度的信息。这些只是示例,但我将如何构建我的模型和数据库,以便它可以很好地处理“自定义的、动态的”列,而不会创建太多空属性。 最佳答案 这里有两个选项。1.NoSQL数据库。2.Rails4Store功能。 关于ruby-on-rails-rails:dynamiccolumns/attributesonmodels?,

ruby - Chef 11 : any way to turn attributes into a ruby hash?

我在chef属性中为我的服务生成一个配置。但是,在某些时候,我需要将属性混搭转换为简单的ruby​​散列。这曾经在Chef10中运行良好:node.myapp.config.to_hash但是,从Chef11开始,这不起作用。只有属性的顶层被转换为散列,然后嵌套值仍然是不可变的混搭对象。修改它们会导致如下错误:Chef::Exceptions::ImmutableAttributeModification------------------------------------------------Nodeattributesareread-onlywhenyoudonotspecif

ruby - 在 ruby​​ 中获取 attr_accessor/实例变量

所以我知道您可以通过调用#instance_variables获取Ruby中的所有实例变量,但如果它们尚未设置,则它们不会显示。示例classWalrusattr_accessor:flippers,:tusksendw=Walrus.neww.instance_variables#=>[]w.tusks#=>nilw.instance_variables#=>[:@tusks]我想立即访问attr_accessor定义的所有实例变量。w=Walrus.neww.instance_variables#=>[:@tusks,:@flippers] 最佳答案

ruby - 从 Jekyll 插件返回目录中的文件列表?

我不知道如何在jekyll插件中创建过滤器或标签,以便我可以返回目录并循环遍历其内容。我找到了这些:http://pastebin.com/LRfMVN5Yhttp://snippets.dzone.com/posts/show/302到目前为止我有:moduleJekyllclassFilesTag我可以成功地将图像列表作为字符串返回并打印:{%filestest_string%}但对于我来说,无论我如何从Dir.glob返回数组/散列,我都无法遍历数组。我只想能够做到:{%forimageinfiles%}image{%endfor%}我将需要能够为我将在网站上使用的各种集合不断返

ruby-on-rails - Rails 3 如何允许在没有_attributes 指定的情况下传递嵌套属性

当使用accepts_nested_attributes_for时,我不想传递“child_attributes”,而是传递“child”。我很确定,如果我在我的Controller中放入大量逻辑来创建记录和子项,我就可以完成此操作。但是,为了使我的Controller保持干净和逻辑应有的位置,即本例中的模型,我想知道如何在执行POST或PUT时切换rails3以使用此语法。{"name":"test","child_attributes":[{"id":1,"name":"test_child_update"},{"name":"test_child_create"}}相当{"nam

ruby-on-rails - Ruby on Rails : How to validate nested attributes on certain condition?

我有这些模型:classOrganisation:addressable,:dependent=>:destroyaccepts_nested_attributes_for:address,:allow_destroy=>trueendclassPerson:addressable,:dependent=>:destroyaccepts_nested_attributes_for:address,:allow_destroy=>true#Thesetwomethodsseemtohavenoeffectatall!validates_presence_of:organisation,:

ruby-on-rails - Rails 4 强参数 : can I 'exclude' /blacklist attributes instead of permit/whitelist?

我正在将Rails3应用程序迁移到Rails4,并且正在将attr_accessible属性转换为Controller中的强参数。APIDocumentation显示如何“允许”属性:defperson_paramsparams.require(:person).permit(:name,:age)end然而,我的绝大多数属性都是批量分配安全的。我只需要将:account_id和:is_admin等几个属性列入黑名单。是否可以将属性列入黑名单而不是将几乎所有属性列入白名单?例如:defuser_paramsparams.require(:user).exclude(:account_i

ruby-on-rails - ruby 或 rails 中有序数到基数的函数吗?

我正试图找到一种更好的方式来表达我的cucumber,所以我正在寻找一个将其转换为基数的函数:WhenIfillupthefirstpassengerfieldThenIshouldseethepassengerlistupdatewiththefirstpassengerdetailsWhenIfollow"AddAnotherPassenger"ThenIshouldseeasecondpassengerfieldWhenIfillupthesecondpassengerfieldThenIshouldseethepassengerlistupdatewiththesecondpa

ruby-on-rails - ActiveModel 属性

如何获得ActiveRecord属性方法功能?我有这个类:classPurchaseFormincludeActiveModel::ValidationsincludeActiveModel::ConversionextendActiveModel::Namingattr_accessor:name,:surname,:emailvalidates_presence_of:namevalidates_format_of:email,:with=>/^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/idefinitialize(attribut

ruby-on-rails - 错误 : When assigning attributes, 您必须将散列作为参数传递

嗨,我刚开始使用ruby​​,我正在编写Controller和Controller规范,但我遇到了一些问题。文档.rbclassDocument文档Controller.rbclassAPI::DocumentsControllerdocuments_controller_spec.rbdescribe"POST'index'"dobefore{@attr=FactoryGirl.attributes_for(:document)}describe"failure"dodescribe"withmissingparameters"dobefore{@attr.each{|key,val