草庐IT

IDEA关联gitlab

全部标签

ruby-on-rails - 多态关联

如果您有多态的belongs_to关联,那么引用将添加所需的两个列:create_table:productsdo|t|t.references:attachment,:polymorphic=>{:default=>'Photo'}end将添加一个attachment_id列和一个默认值为“Photo”的字符串attachment_type列。这到底是什么意思? 最佳答案 这里是引用方法的文档:http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Ta

ruby-on-rails - 通过与其他属性关联的 has_many 的 Rails 形式?

如何为具有附加属性的has_many:through关联生成表单字段?has_many:through关系有一个名为weight的附加列。这是连接表的迁移文件:create_table:users_widgetsdo|t|t.integer:user_idt.integer:widget_idt.integer:weightt.timestampsend模型看起来像这样:Userhas_many:widgets,:through=>:users_widgets,:class_name=>'Widget',:source=>:widgethas_many:users_widgetsacc

ruby-on-rails - 安装 gitlab-5.0 时遇到问题 - rake 中止

安装gitlab-5.0时遇到问题https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md#initialise-database-and-activate-advanced-featuresroot@ubuntu:/home/gitlab/gitlab#bundleexecrakegitlab:setupRAILS_ENV=productionrakeaborted!Accessdeniedforuser'root'@'localhost'(usingpassword:YES)/h

ruby-on-rails - 在运行时查找 ActiveRecord 类的关联?

我想在运行时找到ActiveRecord类的关联...假设我有以下内容:classPerson如何在运行时发现Person“有很多”椅子和笔,反之亦然?我正在寻找一种返回字符串数组的方法(如果存在这样的方法)。即Person.has_many_assocations会返回:["chairs","pens"]和Pen.belongs_to_associations会返回:["person"]我是否遗漏了这样一种存在的方法??感谢您的帮助。 最佳答案 我认为ActiveRecord::Reflection类可能是你要找的。来自文档:Ac

ruby-on-rails - Ruby on Rails 在保存之前通过关联对象 has_many

在RubyonRails项目中,我试图在将所有内容保存到数据库之前访问ActiveRecord上的关联对象。classPurchase如果我像这样构建我的对象:purchase=Purchase.new(item_ids:[1,2,3])并尝试保存它item_validation方法还没有填充项目集合,所以即使虽然项目已经设置,但它没有机会调用任何项目的check_something方法。是否可以在我的购买模型和关联模型保留之前访问项目集合,以便我可以对它们运行验证?如果我将item_validation方法更改为:defitem_validationpurchase_items.ea

ruby-on-rails - 通过关联获取 has_many 的 ActiveRecord::RecordInvalid 错误;连接表上的验证问题

我有如下三个关联模型:classProduct当我做类似的事情时:doc=user.documents.builddoc.update_attributes(:product_ids=>[1,2])并且description验证失败,然后我得到false和doc上的相应错误。这正是我想要的。但是,如果doc已经存在,例如:doc=user.documents.firstdoc.update_attributes(:product_ids=>[1,2])并且description验证失败,然后我得到一个ActiveRecord::RecordInvalid错误。我很清楚为什么会这样——i

ruby - IntelliJ IDEA "Cannot find ' 需要'"

将Ruby插件与IntelliJ一起使用时,我应该期望/容忍哪些“undefinedreference”警告,以及哪些表明我没有正确配置的内容?例如,我收到关于“require”、“File”和“FileUtils”的“无法找到”警告。我怀疑这表示存在配置问题。我还收到有关RSpec方法的警告,例如“描述”、“之前”、“之后”和“它”。我还应该能够配置IntelliJ来“找到”这些吗? 最佳答案 需要在项目结构中选择RubySDK(Ctrl+Alt+Shift+S默认情况下)。不幸的是,它没有解决rspec相关词的警告。

ruby - Rails 中的 FactoryGirl - 具有唯一约束的关联

这个问题是对这里提出的问题的扩展:Usingfactory_girlinRailswithassociationsthathaveuniqueconstraints.Gettingduplicateerrors所提供的答案对我来说非常有效。这是它的样子:#Createsaclassvariableforfactoriesthatshouldbeonlycreatedonce.moduleFactoryGirlclassSingleton@@singletons={}defself.execute(factory_key)begin@@singletons[factory_key]=Fa

ruby-on-rails - 如何只输入唯一关联?

运行以下代码以添加关联,每次运行代码时都会输入多个条目:store.categories有没有办法让它只输入数据库中两个模型之间的唯一关联? 最佳答案 直接来自railsguides,希望对您有所帮助:classPersonhas_many:readingshas_many:posts,:through=>:readings,:uniq=>trueend 关于ruby-on-rails-如何只输入唯一关联?,我们在StackOverflow上找到一个类似的问题:

ruby-on-rails - 如何销毁两个模型之间的所有关联数据? (Rails 初学者)

我有两个模型:store和category以及一个名为categories.stores的连接表。如何删除连接表中商店对象的所有关系数据?我可以使用其中之一吗:store.categories.destroy或category.stores.destroy注意:两个模型都是has_and_belongs_to_many(因此每个关联记录都没有标识符——只有store_id和category_id) 最佳答案 在has_and_belongs_to_many关联中,您可以使用delete_all或destroy_all。在has_ma