我感到困惑之间的主要区别(S) link_to
,redirect_to
并render
在轨道上.任何人都可以请解释.
ruby ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 ruby-on-rails-3.2
我有一个数据库模型Position(lat,lon)
,其中包含latitudes
和longitudes.
我有一个控制器动作show_close_by
,它以度数接收位置(my_lat, my_lon)
,公差(以公里为单位),并应返回数据库中位于公差范围内的位置列表.
为此,我使用hasrsine_distance公式计算两个坐标之间的公里(在地球表面上)的距离(lat1, lon1, lat2, lon2)
.
为了使查询更快,我在查询中编写了整个haversine_distance
公式:
... WHERE 2*6371*asin(sqrt( power( sin( (:lat2-latitude)*pi()/(180*2) ) ,2) + cos(latitude*pi()/180)*cos(:lat2*pi()/180)*power(sin( (:lon2-longitude)*pi()/(180*2) ),2) )) < tolerance
Run Code Online (Sandbox Code Playgroud)
查询的细节无关紧要.我的疑问是:是否有必要为数据库中的每个位置计算这个巨大的函数?我可以使用更简单的功能过滤掉一些显然距离太远的位置吗?
好吧,我可以:使用嵌套的SQL查询,我可以在数据库中查询大"正方形"(在纬度/经度空间内)的位置,然后使用更昂贵的三角函数过滤那些位置.类似于以下内容:
SELECT * FROM ( SELECT * FROM Positions WHERE lat-latitude < some_reasonable_upper_bound AND lon-longitude < same_upper_bound ) WHERE costly_haversine_distance < tolerance
Run Code Online (Sandbox Code Playgroud)
最后,我的问题是:如何在Rails中实现这一点(不自己编写整个查询)?是否Positions.where(reasonable_upper_bound).where(costly_but_accurate_restriction)
进行嵌套查询?如果没有,怎么样?
非常感谢!
我正在从 mean.io 克隆建立一个新的平均项目。安装 npm 包并启动 mongod 后。我运行npm start
它给了我这个错误。
Error: Config validation error: child "JWT_SECRET" fails because ["JWT_SECRET" is required]
Run Code Online (Sandbox Code Playgroud)
这是我的 config.js
const Joi = require('joi');
// require and configure dotenv, will load vars in .env in PROCESS.ENV
require('dotenv').config();
// define validation for all the env vars
const envVarsSchema = Joi.object({
NODE_ENV: Joi.string()
.allow(['development', 'production', 'test', 'provision'])
.default('development'),
SERVER_PORT: Joi.number()
.default(4040),
MONGOOSE_DEBUG: Joi.boolean()
.when('NODE_ENV', {
is: Joi.string().equal('development'),
then: Joi.boolean().default(true),
otherwise: Joi.boolean().default(false)
}),
JWT_SECRET: Joi.string().required()
.description('JWT Secret required to sign'), …
Run Code Online (Sandbox Code Playgroud) 我要将狂欢应用程序从1.3升级到spree版本2-0-stable.任何人都可以请解释确切的步骤或链接以遵循.提前致谢.
我有一个左侧边栏,位置固定.我想要实现的是,当我滚动大约50或60像素时,左侧边栏的位置应该更改为固定.
左sidebar.component.ts
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'left-sidebar',
templateUrl: 'left-sidebar.html',
styleUrls: ['left-sidebar.scss']
})
export class LeftSideBarComponent {
}
Run Code Online (Sandbox Code Playgroud)
左sidebar.html
<div class="col-sm-2 left-nav">
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.left-nav {
position: absolute;
background: #424242;
height: 100%;
overflow: auto;
padding: 0;
z-index: 1;
}
Run Code Online (Sandbox Code Playgroud)
如何在滚动条上将左侧边栏的位置从绝对位置更改为固定位置?
我需要在后台运行一个视频.要求视频必须在100%宽度和600px高度/最大高度上运行.这是我试图做的.
https://jsfiddle.net/yydkd5t4/1/
HTML
<video autoplay loop muted id="video-bg">
<source src="http://demosthenes.info/assets/videos/polina.mp4" type="video/mp4">
</video>
Run Code Online (Sandbox Code Playgroud)
CSS
#video-bg {
position: fixed;
right: 0;
bottom: 0;
width: auto;
min-width: 100%;
height: auto;
min-height: 100%;
z-index: -100;
background: transparent url(video-bg.jpg) no-repeat;
background-size: cover;
}
video {display: block;}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,当我尝试修复高度时,它也会缩小宽度.任何解决我的问题的方法都将受到高度赞赏.