在 Git 中,暂存区也称为索引。似乎是说,当您在工作目录中进行更改并将这些更改添加到“暂存”时,git 会将这些文件添加到索引文件中。打开项目 /.git/index 文件时,我看到一个文件,其中包含在我键入时显示的文本:
git status
Run Code Online (Sandbox Code Playgroud)
我可能会得到如下所示的输出:
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: Gemfile
#
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
但是在其他地方,例如Git Index Contents,他们通过键入以下内容来表示:
git ls-files --stage
Run Code Online (Sandbox Code Playgroud)
您可以看到索引的内容.. 虽然这显然不是 /.git/index 中的内容。.git 目录中的哪个文件实际上包含此索引?我怀疑,我可能是错的.. .git/index 将更改信息存储在“修改”行中,然后在键入 git ls-files --stage 时,它正在构建文件列表基于工作目录中的文件和在此索引文件中列为已修改的文件进行暂存及其散列。这是正确的吗?
我有一个类Ryte :: Theme.如果我在类上调用included_modules,我会回来(缩写):
[Ryte :: Bundleable :: Core,Ryte :: Bundleable :: Validators,Ryte :: Bundleable :: Builder,ActiveModel :: Validations :: HelperMethods,ActiveModel :: Validations,ActiveSupport :: Callbacks,Ryte :: Bundleable]
Ryte :: Theme通过单个模块Ryte :: Bundleable拉入嵌套模块.以下是相关的类和模块定义:
class Ryte::Theme
include Ryte::Bundleable
end
module Ryte::Bundleable
extend ActiveSupport::Concern
included do
include ActiveModel::Validations
include Ryte::Bundleable::Builder
include Ryte::Bundleable::Validators
include Ryte::Bundleable::Core
end
end
Run Code Online (Sandbox Code Playgroud)
鉴于此,为什么我收到以下回复:
Ryte::Theme.include?(Ryte::Theme::Validators)
=> true
Run Code Online (Sandbox Code Playgroud)
我还没有包括这个额外的模块..这在included_modules响应中很明显.这与ActiveSupport关注有关吗?我希望能够包含Ryte :: Theme :: Validators并将它混合在一起,但因为它认为它已经被包含在内,所以它不会再次包含它(因为它不应该包含它).因此,当我将include添加到类定义时,它会被遗忘,如下所示:
class Ryte::Theme
include Ryte::Bundleable
include Ryte::Theme::Validators # <- Does not load
end
Run Code Online (Sandbox Code Playgroud)
为什么这个附加模块Ryte :: Theme :: Validators也没有混入?
好吧刚才意识到: …
Mongoid 提供了一些 rake 任务,其中之一为数据库中的所有集合创建索引:
耙 db:create_indexes
但是如果我错了,请纠正我,创建索引与实际索引所有项目是否不同?如何重新索引我的文档?如果我在 Rails 中为新集合添加了索引但数据库中已经有 10,000 个项目,这将是必要的。
我现在已经被问了一千次,但这对我没有帮助嘿:)我已经在这一个小时了.我的表格:
= form_for @comment, :url_for => { :action => "create", :controller => "comments"}, :method => :post
Run Code Online (Sandbox Code Playgroud)
我的佣金路线:
POST /t/:trunk_id/r/:root_id/comments(.:format) {:action=>"create", :controller=>"comments"}
trunk_root_comment GET /t/:trunk_id/r/:root_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"}
Run Code Online (Sandbox Code Playgroud)
错误:
undefined method `comments_path' for #<#<Class:0x007fed2c713128>:0x007fed2c71cc78>
Run Code Online (Sandbox Code Playgroud)
如果我将表格命名为:
= form_for [:trunk_root, @comment], :url_for => { :action => "create", :controller => "comments"}, :method => :post do |f|
Run Code Online (Sandbox Code Playgroud)
应该根据rake路线制作路线trunk_root_comments_path ..这是正确的..我得到:
No route matches {:controller=>"comments", :format=>nil}
Run Code Online (Sandbox Code Playgroud)
非常感谢帮助..已经看了好几个小时..
更新:
谢谢Ryan这么棒的答案!一个非常明确的解释,我只是"扔东西",现在至少我理解得更好.我实际上已经在我的佣金路线中提供了'trunk_root_comments_path',并且我尝试过你提到的几种组合,但我并没有真正讨厌我所缺少的东西,所以你帮了忙.我正在使用Mongo,我实际上没有Trunk模型,我只有一个名为@root.trunk的根属性,虽然我有一个中继控制器,因此它是我的路由的一部分(也许是一个坏主意idk) .
所以我尝试了你的TLDR,它说错误:
Undefined method 'root_comments_path'
Run Code Online (Sandbox Code Playgroud)
..因为没有Trunk模型存在,我假设?..所以我让@trunk等于正确的id
= form_for [@trunk, @root, @comment] do |f|
Run Code Online (Sandbox Code Playgroud)
< - 我得到'未定义的方法`politics_root_comments_path''..我认为......这可能是有道理的......因为我失败了我必须尝试你最明确的版本:
= form_for @comment, …Run Code Online (Sandbox Code Playgroud) 有没有办法进行第二次查询并复制预先加载的功能?让我们说一个真实的基本例子.一个人有很多车,一辆车有很多零件..
通常情况下,你会说:
person.cars.includes(:parts)
Run Code Online (Sandbox Code Playgroud)
我真的不明白这是做什么的......它只是在内存中加载其他对象吗?它们是否在这一点上与每辆车相关联,然后只是共享密钥?如果只是共享密钥..我可以在内存中加载这些"部件"并在不明确调用"包含"的情况下访问它们吗?例如..类似于:
cars = person.cars
cars_id_array << insert cars ids here
parts = Parts.where(:user_id => person_id, "car_id IN cars_id_array") (just an example)
Run Code Online (Sandbox Code Playgroud)
在这种情况下(假设我做了写代码,我确定我没有..我可以去car1.parts,car2.parts,那些部分是否已经加载到内存中?
如果不是,那么渴望加载的是什么?