我在我网站的主页上使用ElasticSearch.在我的验收测试中,当用户登录时,他被重定向到主页.
但是在测试中使用ES是昂贵的(需要创建和删除索引),因此我不希望每次用户浏览主页时都这样做.
我想只在测试有一些元数据时才进行实际的ES搜索:
config.before(:each) do
if example.metadata[:elastic]
Model.create_elasticsearch_index
end
end
scenario "Results should be ordered by distance", :elastic do
# tests...
end
Run Code Online (Sandbox Code Playgroud)
因此,我需要"模拟"搜索,而不是在测试没有弹性元数据时使用ES.
什么是实现这一目标的好方法?
似乎是一个非常简单的想法,但我不知道如何从select2下拉列表中筛选出原始选择的选项标签。
基本上,这是:
<select id="select">
<option class="car">Car 1</option>
<option class="plane">Plane 1</option>
</select>
$("#select").select2();
Run Code Online (Sandbox Code Playgroud)
...应该只创建带有class的option标记的假选择car。
我有一个活动模型.它belongs_to :parent, :polymorphic => true.
是否Rails的使用parent.class.name,parent.model_name还是其他什么东西来填充PARENT_TYPE场?
我希望Presenter的行为与它包装的父对象相似,我需要覆盖正确的方法.
谢谢.
ruby-on-rails presenter polymorphic-associations ruby-on-rails-3
development.rb,我有config.cache_classes = false我有一个非常奇怪的行为.假设我在日志中输出了一些东西:Rails.logger.warn "Hello"
如果我重新加载页面,我会在日志中看到"Hello".如果删除它,它将消失.但如果我再把它放回去,它就不会出现......
此外,raise "Fail!"模型中的简单将导致异常正常引发.但是如果我删除raise并重新加载页面,它仍然会引发异常.
这是怎么回事?
我正在寻找一个使用Ember数据的Ember开源或示例应用程序,它依赖于API并处理服务器端验证.
我很难找到使用Ember和Ember数据处理服务器端验证的良好,标准方法的示例.
在指南中,我可以看到两种方法来定义资源的路径,我想知道我应该使用的是什么,为什么?
在这里找到:http://emberjs.com/guides/routing/defining-your-routes/
App.Router.map(function() {
this.resource('posts');
this.resource('post', { path: '/posts/:post_id' });
});
Run Code Online (Sandbox Code Playgroud)
在此处找到:http://emberjs.com/guides/templates/links/
App.Router.map(function() {
this.resource("posts", function(){
this.route("post", { path: "/:post_id" });
});
});
Run Code Online (Sandbox Code Playgroud)
我发现很奇怪有定义2个资源,posts并且post,当它实际上只是一个Post资源.
Item我的Rails应用程序中有一个可搜索的模型.
我想索引ElasticSearch中的大多数,除了满足某些条件的那些.
我怎样才能做到这一点?
update_index在模型中重写可接受的解决方案?
我知道我也可以将它们全部索引,并在搜索中过滤掉它们.但它们永远不会被搜索,所以我根本没有看到索引它们的理由.
我想select使用SimpleForm从数组(而不是模型集合)构建输入,并为每个options创建不同的类.
我希望这会起作用:
f.input :method, collection: [
["option text", "option_value_1", { class: "class_name_1" }],
["option text 2", "option_value_2", { class: "class_name_2" }]
]
Run Code Online (Sandbox Code Playgroud)
问题是它会产生:
<select>
<option value="option text" class="class_name_1">option text</option>
<option value="option text 2" class="class_name_2">option text 2</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我怎样才能以简单的形式做我想要的(价值应该是"期权价值")?
我试图在 3D 环境中利用力量让我的玩家动作敏捷。我尝试了一些事情,但从我的玩家在游戏中的反应来看,我认为我遗漏了一些信息。
public Rigidbody rb;
public float acceleration = 500f;
public UnityEngine.ForceMode forceMode = ForceMode.Impulse;
void Update() {
rb.AddRelativeForce(new Vector3(Input.GetAxis("Horizontal") * acceleration * Time.deltaTime, 0, Input.GetAxis("Vertical") * acceleration * Time.deltaTime), forceMode);
rb.velocity = Vector3.zero;
}
Run Code Online (Sandbox Code Playgroud)
首先,为什么这段代码仍然允许我移动我的玩家?每帧将速度重置为 0 应该可以防止它移动,不是吗?我猜即使速度始终设置为 0,力仍然会施加在后续帧上?
我应该如何使用力来获得真正快速的运动,当我停止按 UP 时,施加在 Z 轴上的力就会“停止”?
我有 2 个型号,Player并且Item. Aplayer有很多items.
模型的映射Item:
tire do
mapping(
_parent: { type: 'player' },
_routing: { required: true, path: :user }
) do
indexes :user, type: "string", index: :not_analyzed
end
Run Code Online (Sandbox Code Playgroud)
(不确定该path选项是什么,除了它可能用于将项目存储在不同的分片上?
我不明白的是如何player在保存item. 在我在网上找到的所有父/子关系示例中,他们只是使用 CURL:
curl -XPOST localhost:9200/authors/book/1?parent=2 -d '{
"name": "Revelation Space",
"genre": "scifi",
"publisher": "penguin"
}'
Run Code Online (Sandbox Code Playgroud) tire ×3
ember.js ×2
ember-data ×1
forms ×1
javascript ×1
jquery ×1
model ×1
presenter ×1
reload ×1
routes ×1
rspec ×1
select ×1
simple-form ×1
validation ×1