草庐IT

attribut

全部标签

ruby-on-rails - 具有 mongoid 的许多对象的 update_attributes

可能是这样的:@users=User.criteria.for_ids(params[:user_ids])@users.update_all(:suspend=>true)代替:foruin@usersu.suspend=trueu.update_attributesend 最佳答案 看看这个:#Updatingonerecord:Person.update(15,:user_name=>'Samuel',:group=>'expert')#Updatingmultiplerecords:people={1=>{"first_na

ruby Chef 指令 : include_attribute vs. include_attributes

我在chef属性文件中看到了这段代码。include_recipe"deployment"include_attribute"postgresql"include_attribute"redis"include_attributes"uaa"include_attributes"service_lifecycle"有什么不同?include_attribute与include_attribute*S*我找不到任何关于include_attribute*S*的文档 最佳答案 include_attribute属性用于对收敛时加载属性文

ruby-on-rails - rails : validation fails with before_create method on datetime attribute

ApiKey.create!抛出验证错误:expires_at不能为空。classApiKey有属性t.datetime:expires_at但是,如果删除了验证,则before_create方法会在创建时起作用。这是为什么?-此模式适用于其他属性,例如access_tokens(字符串)等 最佳答案 我会说因为before_create在验证之后运行,也许您想将before_create替换为before_validation注意:如果你像那样留下回调,它会在你运行valid?或save或任何时候设置到期日期触发验证的事件记录方法

ruby-on-rails - Rails 4 如何从模型中调用 accessible_attributes

您好,我正在尝试这个tutoonRailscast(ImportingcsvExcelfile)。我在这一行product.attributes=row.to_hash.slice(*accessible_attributes)上遇到错误undefinedlocalvariableormethodaccessible_attributes'for#`这是我的模型。classProduct在我的Controller上结束,我定义了product_paramsdefproduct_paramsparams.require(:product).permit(:name,:price,:rel

ruby-on-rails - 使用具有单表继承的 accepts_nested_attributes_for

我有一个模型Post哪个belongs_to一Section.有两个不同的Section子类,我使用STI为每个子类实现不同的行为。在Post我希望每个Section都有一个选项卡.该选项卡将允许用户A)从现有的Section中选择使用或B)让用户创建一个新的Section.我想知道如何使用accepts_nested_attributes_for和fields_for或者完成此操作所需的任何东西TheRailsWay。非常感谢任何建议。谢谢。 最佳答案 假设标签对应两个子类classPost#thetwosubclasses.Ea

ruby-on-rails - rails : Ordering parents by grand children's attribute

classUserhas_many:calendarshas_many:cars,through::calendarsendclassCalendarhas_many:carsendclassCar#attribute`issued_at`end我需要通过issued_at向用户订购他的汽车。因此,通过孙子的属性issued_at对父级进行排序。到目前为止:@q=User.active.joins(:cars).order('cars.issued_at').group('users.id')但是我得到了column"cars.issued_at"mustappearintheGROU

ruby-on-rails - 如何使用 accepts_nested_attributes_for 在连接表中创建 > 1 个相关对象?

我目前有一个非常简单的设计,使用Ruby2.0和Rails4beta创建。我有用户和组。一个用户可以是多个组的成员,一个组可以有多个用户作为成员。因此,我有一个连接模型UserGroup,它只包含user_id和group_id。如下:classUser我发现了很多关于accepts_nested_attributes_for的内容,这些内容似乎显示了在创建/更新时创建了一个关联对象。我想要的是一个多选项选择框,我可以在其中从我希望用户成为其成员的系统中当前所有组的列表中选择多个选项,并在提交时为我生成所有user_group关联。我无法在Controller或View中弄清楚我需要什

ruby-on-rails - 尝试添加 accepts_nested_attributes_for 时缺少 fields_for

我正在开发一个简单的表单功能,它通过嵌套表单添加图像。应该存储我上传的所有图像的照片模型。classPhoto",medium:"300x300>",thumb:"100x100#"},default_url:"/images/:style/missing.png"validates_attachment_content_type:image,content_type:/\Aimage\/.*\Z/end我的嵌套表单片段(在表单内)一切都很好,但是当我取消注释accepts_nested_attributes_for行时。我的嵌套表单消失了!classPosting

ruby-on-rails - rails 3 : Rendering certain attributes of an array of objects in JSON

在我看来,我正在尝试将一些数据传递给javascript。我只想要数组中对象的某些属性。jsongem似乎不支持:only选项。我尝试使用ActiveSupport::JSONtest1=[:left,:width])%>;但这会忽略:only并打印整个对象。然后我想我会很聪明,从Controller中获取render方法:test2=@sections.as_json(:only=>[:left,:width])%>但我收到Nil:Nilclass错误。我还尝试将它放入我的模型中并运行to_json:includeActiveModel::Serialization::JSONdef

ruby-on-rails - Elasticsearch /轮胎 : How to map to association attribute?

我正在使用Tire用于Elasticsearch。在我的应用程序中,我有2个模型;价格和产品。我正在尝试搜索我的Price类并使用它所属的Product的:name属性作为搜索字段。现在,如果我有一个名为Product1的产品并输入“pro”、“prod”或“duct”,则不会出现任何结果。但是键入“product”或“Product”会显示结果。我相信问题出在我的映射上。我查看了查询及其:...localhost:3000/search/results?utf8=%E2%9C%93&query=product当我认为应该是:...localhost:3000/search/resul