我有一个在Heroku中运行的Rails应用程序,以及一个使用Jquery Mobile的html文件.
Rails应用程序返回JSON数据(使用RABL),我的移动应用程序可以选择并显示.
这就是我正在做的事情,我正在将回复的内容提供给列表视图.很简单.如果我使用Chrome,则控制台会显示错误:Access-Control-Allow-Origin不允许使用Origin null.如果我尝试Firefox,控制台上没有错误,但数据也没有显示,甚至没有显示警报触发器.
function getBuses(){
$('#content').append("<ul id='bus_list' data-role='listview' data-inset='true'</ul>")
$('#content').trigger("create");
//Se llama a la API para retornar todos los buses
$.getJSON('http://someapp.herokuapp.com/buses.json', function(data)
{
$.each(data, function(key, value)
{
alert(key + ":" + value);
$('#bus_list').append('<li id="'+bus.id+'">'+bus.numero_de_linea+'<li/>');
});
});
$('#bus_list').listview("refresh");
}
Run Code Online (Sandbox Code Playgroud)
这是服务器响应的内容:
[{"id":7,"numero_de_linea":"604"}]
Run Code Online (Sandbox Code Playgroud)
我已经阅读了Access-Control-Allow-Origin一段时间了,但是我不确定我该做什么,我应该更改服务器中的内容吗?我正在我的浏览器上尝试这个html文件,但它也无法在我的手机上运行.跑步时我已经设定$.support.cors并且$.mobile.allowCrossDomainPages = true;为真mobileinit.
任何有关下一步该怎么做的信息都将不胜感激.
编辑:如果您正在使用RABL,请记住在初始化程序中将变量enable_json_callback设置为true.你必须从双方都启用这个东西.
我正在使用容器进行开发并使用 docker-compose 来提升它们。有时我会运行docker-compose down并重建容器。大多数时候我都会收到这个错误
PG::ConnectionBad (could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
):
Run Code Online (Sandbox Code Playgroud)
我不明白为什么 Rails 抱怨 Postgres 不在那里,如果整个容器都被重新重建了。此外,错误会在一段时间后消失,我没有做任何其他停止、重新启动或重建容器的事情。我转而使用容器进行开发,以精确避免此类烦人的问题。
这是我的内容 docker-compose.yml
version: '2'
services:
users:
build:
context: '.'
links:
- postgres
- redis
volumes:
- ".:/app/users/"
working_dir: /app/users
command: [rails, server, -p, "3000", -b, 0.0.0.0]
ports:
- "3000:3000"
postgres:
image: postgres:9.5
environment:
POSTGRES_DB: somedb
POSTGRES_USER: someuser
POSTGRES_PASSWORD: somepass
redis:
image: redis:latest …Run Code Online (Sandbox Code Playgroud) 我有以下型号
class Measurement < ApplicationRecord
belongs_to :examination, class_name: "TestStructure", foreign_key: "examination_id"
end
Run Code Online (Sandbox Code Playgroud)
该关联实际上是对TestStructure模型进行的,但关联名称是检查.没有检查表.
当我查询使用时出现问题join.以下查询
Measurement.joins(:examination).where(examination: { year: 2016, month: 5 })
Run Code Online (Sandbox Code Playgroud)
失败,出现此错误
ActiveRecord::StatementInvalid:
PG::UndefinedTable: ERROR: missing FROM-clause entry for table "examination"
LINE 1: ...d" = "measurements"."examination_id" WHERE "examinati...
# --- Caused by: ---
# PG::UndefinedTable:
# ERROR: missing FROM-clause entry for table "examination"
# LINE 1: ...d" = "measurements"."examination_id" WHERE "examinati...
Run Code Online (Sandbox Code Playgroud)
很明显,该examinations表不存在,但我找不到告诉ActiveRecord我使用命名关联而不是默认关联的方法.
任何见解?
我正在使用 Tirexs 包构建自己的用于处理 ElasticSearch 的代码库。这是我第一次深入研究宏、依赖项、使用、导入和 Elixir 提供的其他几个最高级的功能。
为此,我定义了一个Document大致如下所示的结构,( /lib/data/document.ex)
defmodule Document do
use Document.ORM
import Document.Builder, only: [build_document: 2]
import Document.Builder.Validations, only: [is_document_valid?: 1, collect_errors: 1]
defstruct [valid?: false, errors: nil, fields: %{}]
def something do
# uses imported functions from Document.Builder and Documen.Builder.Validations
end
end
Run Code Online (Sandbox Code Playgroud)
然后Document模块使用模块中的其他几个Document.ORM似乎不是错误原因的函数。
我的错误如下
Compilation failed because of a deadlock between files.
dataobj_1 | The following files depended on the following modules:
dataobj_1 |
dataobj_1 | web/controllers/document_controller.ex …Run Code Online (Sandbox Code Playgroud) 我正在iOS中的Android中使用Rails 4 API后端和移动应用程序.使用Nginx和Unicorn.
要获取某些数据,cliens必须在请求的标题中向我发送(以及其他内容)用户ID.我们正在使用自定义标头,例如WWW_CUSTOM_NAME,此处说明.我知道在Rails 4中,我可以通过执行类似的操作捕获这些自定义标头中的值
request.headers["HTTP_WWW_CUSTOM_NAME"]
Run Code Online (Sandbox Code Playgroud)
事实上,我和我的团队每次都在开发中工作.但是当我们将代码推送到生产服务器时,这种方法并不起作用.
这几乎就像自定义标题在生产中消失了.我尝试了同样的事情,没有额外的"HTTP_",删除大写字母,没有任何效果.但在开发工作中没问题.
知道为什么一定是这个吗?