从下面的代码中,当我打电话时conn.params["geo"]
,我收到以下错误:
test/plugs/geoip_test.exs:4
** (UndefinedFunctionError) function Plug.Conn.Unfetched.fetch/2 is undefined (Plug.Conn.Unfetched does not implement the Access behaviour)
stacktrace:
(plug) Plug.Conn.Unfetched.fetch(%{:__struct__ => Plug.Conn.Unfetched, :aspect => :params, "geo" => "Mountain View, US", "ip" => "8.8.8.8"}, "geo")
Run Code Online (Sandbox Code Playgroud)
...
defmodule AgilePulse.Plugs.GeoIPTest do
use AgilePulse.ConnCase
test "returns Mountain View for 8.8.8.8" do
conn = build_conn
params = Map.put(conn.params, "ip", "8.8.8.8")
conn = Map.put(conn, :params, params) |> AgilePulse.Plugs.GeoIP.call(%{})
assert conn.params["geo"] == "Mountain View, US"
end
end
defmodule AgilePulse.Plugs.GeoIP do
import Plug.Conn
def init(opts), do: opts
def …
Run Code Online (Sandbox Code Playgroud) 我是第一次用凤凰应用程序设置监护人.我正在使用Guardian Config中的密钥敲打路障.我不知道在哪里保密密钥以及如何生成密钥?我基本上是从自述文件中复制并粘贴的,我确信这不正确,但我似乎无法在这个问题上找到合适的文档.以下是我尝试与数据库中的用户创建会话时遇到的问题.
erlang error: {:not_supported, ["P-521", :HS512]}
这是我当前的配置文件,这显然是错误的.
config :guardian, Guardian,
issuer: "PerriAir",
ttl: { 30, :days },
verify_issuer: true, # optional
secret_key: %{
"crv" => "P-521",
"d" => "axDuTtGavPjnhlfnYAwkHa4qyfz2fdseppXEzmKpQyY0xd3bGpYLEF4ognDpRJm5IRaM31Id2NfEtDFw4iTbDSE",
"kty" => "EC",
"x" => "AL0H8OvP5NuboUoj8Pb3zpBcDyEJN907wMxrCy7H2062i3IRPF5NQ546jIJU3uQX5KN2QB_Cq6R_SUqyVZSNpIfC",
"y" => "ALdxLuo6oKLoQ-xLSkShv_TA0di97I9V92sg1MKFava5hKGST1EKiVQnZMrN3HO8LtLT78SNTgwJSQHAXIUaA-lV"
},
serializer: PerriAir.GuardianSerializer
Run Code Online (Sandbox Code Playgroud)
关于如何生成正确密钥的任何提示都会很棒谢谢!
我在 nginx 后面设置了 Phoenix 应用程序。Nginx 正在提供 https 流量。
我希望来自 Coherence 的电子邮件包含 https 网址,例如https://my_domain.com/...
,但我不知道如何做到这一点。
这是我的应用程序的配置:
config :my_app, MyApp.Endpoint,
http: [port: 8080],
url: [host: "my_domain.com", port: 443],
# ...
Run Code Online (Sandbox Code Playgroud)
使用此配置,电子邮件中的 URL 如下所示:my_domain.com:443/some_path
。当我移除时port: 443
,它们就变成了my_domain.com:8080/some_path
。并且添加force_ssl: [hsts: true]
也没有帮助。
当然,我可以设置url: [host: "my_domain.com", port: 80]
nginx 将所有 http 请求重定向到端口 443,但这对我来说似乎是错误的。我可以编辑电子邮件模板来强制使用 https url,但这似乎也是错误的。
或者也许在 erlang 应用程序前面使用代理不是 erlang 方式,而我只是还没有得到它?
我有时间作为"2011-12-03 12:00:19"如何在"2011年12月2日星期五"转换它,我知道这个http://docs.oracle.com/javase/6/docs/api/ java/text/SimpleDateFormat.html,但是给了我错误:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at com.timestamp.NewTimeStamp.<init>(NewTimeStamp.java:21)
at com.timestamp.NewTimeStamp.main(NewTimeStamp.java:35)
Run Code Online (Sandbox Code Playgroud)
我的代码是::
String mytime ="2011-12-03 12:00:19";
String pattern = "EEE d MMMMM yyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
Date date = new Date(mytime);
String time = dateFormat.format(date);
System.out.println("=== > " + time);
Run Code Online (Sandbox Code Playgroud) 我正在和凤凰+ Ecto一起玩,我偶然发现了一些对我来说不太惯用的东西.
我有一个代表一个表格Invitation
.在创建邀请时,我们还需要创建一个User
,显然我希望两者都在事务中发生,因此我保持数据一致性.以我的形式,我要求name
和email
.
因为我希望Invitation
我的视图中的变更集正确地表示错误,所以我最终得到了这个代码...但看起来不太好.
你知道在Phoenix + Ecto有更好的方法吗?
def create(params) do
Repo.transaction(fn ->
case Repo.insert(User.email_changeset(%User{}, params)) do
{:ok, user} ->
changeset = Invitation.changeset(%Invitation{}, params)
case Repo.insert(Ecto.Changeset.change(changeset, user_id: user.id)) do
{:ok, user} ->
user
{:error, changeset} ->
Repo.rollback(changeset)
end
{:error, _changeset} ->
Repo.rollback(%{Ecto.Changeset.add_error(changeset, :email, "Wrong email") | action: :insert})
end
end)
end
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置网络套接字以通过 Nginx 访问 Phoenix 应用程序,但不断收到 403 错误。任何人都可以建议正确的配置以使其在生产中工作 - 开发环境很好。
我的 Nginx 配置:
upstream phoenix {
server 127.0.0.1:4000 max_fails=5 fail_timeout=60s;
}
server {
server_name <app-domain>;
listen 80;
location / {
allow all;
# Proxy Headers
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Cluster-Client-Ip $remote_addr;
# The Important Websocket Bits!
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://phoenix;
}
}
Run Code Online (Sandbox Code Playgroud)
我的 prod.exs conf:
use Mix.Config
config :logger, level: :info
config :phoenix, :serve_endpoints, true
config :app, App.Endpoint,
http: [port: 4000],
url: …
Run Code Online (Sandbox Code Playgroud) 当我尝试运行mix deps.get
或mix deps.compile
收到此错误时:
== Compilation error on file lib/phoenix_ecto/html.ex ==
** (CompileError) lib/phoenix_ecto/html.ex:3: unknown key :model for struct Ecto.Changeset
(stdlib) lists.erl:1354: :lists.mapfoldl/3
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况,我该如何解决?
我知道两者之间的区别; assoc_constraint
使用ecto模式验证外键约束,foreign_key_constraint
使用db.
你为什么要用assoc_constraint
这种情况?
我的操作系统是最新的macOS high sierra.我通过Homebrew安装了elixir和所有依赖项.我创建了一个新的Phoenix应用程序.它显示出一些错误.实时重新加载不起作用.以下是信息.
[error] Can't find executable `mac_listener`
[warn] Could not start Phoenix live-reload because we cannot listen to the file system.
You don't need to worry! This is an optional feature used during development to
refresh your browser when you save files and it does not affect production.
Run Code Online (Sandbox Code Playgroud)
似乎某些文件更改侦听器服务未运行.但我不知道如何解决它.