草庐IT

accepts-nested-attributes

全部标签

ruby-on-rails - Rails,activerecord : self[:attribute] vs self. 属性

在Rails中访问事件记录列/属性时,使用self[:attribute]与self.attribute有什么区别?这会影响getter和setter吗? 最佳答案 它们都只是获取属性的方法-它们都只是getter。self.attribtue是一个更“传统”的getter,而self[:attribute]基本上只是[]方法。在使用两者之间切换不会产生任何影响。我建议只使用self.attribute方法,因为它在语法上更好。但是,当其他内容覆盖self.attribute方法时,使用self[:attribute]会派上用场。例

ruby-on-rails - Elasticsearch /轮胎 : How do I filter a boolean attribute?

我想过滤我类(class)的私有(private)bool值,以便它只显示非私有(private)但对我不起作用的资源。(我大大简化了代码)mappingdoindexes:private,type:"boolean"indexes:name,type:"string"endenddefself.search(params)tire.search(load:true,page:params[:page],per_page:20)doquery{stringparams[:query]}ifparams[:query].present?#SofarI'vetried...#filter:

ruby-on-rails - 尝试使用 accepts_nested_attributes_for 和 has_and_belongs_to_many 但未填充连接表

我正在学习RoR并尝试使用accepts_nested_attributes_for和has_and_belongs_to_many来提交传统上为两种形式的信息。我在一些网站上看到它们兼容,一些网站不兼容,还有一些网站不知道。作为引用,我使用的是Rails2.3.4。我尝试根据nestedmodels上的Ryan'sScraps教程对我的解决方案进行建模从我尝试调试的内容来看,我似乎有两个问题,但我不确定为什么。当我提交包含嵌套模型的表单时,只发布了部分嵌套模型信息。我只得到第一个字段,而不是用户可能选择的“n”个其他字段在发布的单个字段中,没有任何行插入到我为HABTM关系创建的连接

ruby-on-rails - rails : How to test if an attribute of a class object is required in the model policy?

简单地说,我有一个模型用户,其中包含名称、电子邮件和评论作为属性。validates_presence_of:namevalidates_presence_of:email所以“姓名”和“电子邮件”是必需的,但不是“评论”。my_user=User.new我想找到一种方法来测试像my_user.name.required?或User.name.required?类似的东西。我的目标是创建一个表单,并根据该项目是否设置为“validates_presence_of”,将特定类动态添加到表单项目span或td我试图搜索它,但没有找到任何相关信息。有没有简单的方法可以做到这一点?谢谢

ruby-on-rails - accepts_nested_attributes_for 忽略空白值

我有classProfilehas_many:favorite_books,:dependent=>:destroyhas_many:favorite_quotes,:dependent=>:destroyaccepts_nested_attributes_for:favorite_books,:allow_destroy=>trueaccepts_nested_attributes_for:favorite_quotes,:allow_destroy=>trueend我有一个动态表单,您可以在其中按“+”添加新的文本区域以创建新的收藏夹。我想要做的是忽略空白的,我发现这比非嵌套属性更

ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行rakedb:migrate或运行railss命令时,我得到同样的错误:Error:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/var/run/postgresql/.s.PGSQL.5432"?当我尝试railss时,浏览器出现错误。这是我的database.ymldefault:&defaultadapter:postgresqlencoding:unicodepool:5development

jquery - Rails accepts_nested_attributes_for 与 f.fields_for 和 AJAX

我很好奇如何正确使用accepts_nested_attributes_for和f.fields_for。views/orders/new.html.erbDetailsviews/order_details/_details.html.erb$$$→|length:|width:|height:|weight:controllers/orders_controller.rb(我很确定这是错误的......非常感谢这里的任何帮助)defcreate@order=Order.create(params[:order])if@order.saveflash[:success]=

ruby-on-rails - 警告 : Can't mass-assign protected attributes

当发帖到/:username/about时,我收到“警告:无法批量分配protected属性:about”。classAbout["lower(username)=?",params[:username].downcase])iftrue@about=@user.aboutif@about.update_attributes(params[:about])flash[:notice]="Successfullyupdatedpost."respond_with(@about,:location=>about_path(@about.user.username))elseredirect

ruby-on-rails - 切换到 Rails 4.1 时出现错误 - `method_missing':ActiveRecord::Base:Class (NoMethodError) 的未定义方法 `whitelist_attributes='

从Rails4.0切换到Rails4.1时出现此错误:activerecord-4.1.8/lib/active_record/dynamic_matchers.rb:26:in`method_missing':undefinedmethod`whitelist_attributes='forActiveRecord::Base:Class(NoMethodError)我没有在我的应用程序的任何地方使用attr_accessible或attr_protected所以我想知道为什么我有问题。当迁移到Rails4.0时,我已经安装了我的application.rb:配置/应用程序.rb:c

ruby-on-rails - rails : Copying attributes from an object to another using the "attributes" method

让模型Quote具有属性[price,description]让模型Invoice有属性[price,description,priority]让invoice模型Invoice中的对象具有属性{price:10,description:'lamp',priority:10}invoice={price:10,description:'lamp',priority:10}假设我想将invoice属性复制到新的quote。quote=Quote.new(invoice.attributes)这会引发一个错误,即priority在模型Quote中不存在。如何将invoice属性复制到新的q