mix compile
==> gettext
could not compile dependency :gettext, "mix compile" failed. You can recompile this dependency with "mix deps.compile gettext", update it with "mix dep
s.update gettext" or clean it with "mix deps.clean gettext"
==> oblako
** (Mix) Could not compile "src/gettext_po_parser.yrl" because the application "parsetools" could not be found. This may happen if your package manager
broke Erlang into multiple packages and may be fixed by installing the missing "parsetools" package for Erlang.
Run Code Online (Sandbox Code Playgroud) 我是 Elixir 和 Phoenix 的新手。我试图为几个迁移文件运行迁移,mix ecto.migrate但它抛出了这个错误,
18:27:24.471 [info] == Running FatLobster.Repo.Migrations.CreateRecipeTable.change/0 forward
** (Ecto.MigrationError) cannot execute command outside of block
(ecto) lib/ecto/migration/runner.ex:139: Ecto.Migration.Runner.subcommand/1
_build/dev/lib/fat_lobster/priv/repo/migrations/20160423115340_create_recipe_table.exs:5: FatLobster.Repo.Migrations.CreateRecipeTable.change/0
(stdlib) timer.erl:197: :timer.tc/3
(ecto) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/6
(ecto) lib/ecto/migrator.ex:121: Ecto.Migrator.attempt/6
(ecto) lib/ecto/migrator.ex:71: anonymous fn/4 in Ecto.Migrator.do_up/4
(ecto) lib/ecto/pool.ex:292: Ecto.Pool.with_rollback/3
(ecto) lib/ecto/adapters/sql.ex:582: Ecto.Adapters.SQL.transaction/8
(ecto) lib/ecto/pool.ex:244: Ecto.Pool.outer_transaction/6
(ecto) lib/ecto/adapters/sql.ex:551: Ecto.Adapters.SQL.transaction/3
(ecto) lib/ecto/migrator.ex:226: anonymous fn/4 in Ecto.Migrator.migrate/4
(elixir) lib/enum.ex:1088: Enum."-map/2-lists^map/1-0-"/2
(ecto) lib/mix/tasks/ecto.migrate.ex:63: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
(elixir) lib/enum.ex:604: Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:604: Enum.each/2
(mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
(elixir) lib/code.ex:363: …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) 总长生不老药菜鸟在这里。这是我的问题:
使用Enum.all?/2函数时,我们传递一个函数作为第二个参数:
iex(19)> is_int = &(is_integer(&1))
iex(20)> Enum.all?(list, is_int)
true
Run Code Online (Sandbox Code Playgroud)
那为什么我不能is_integer直接通过呢?
iex(21)> Enum.all?(list, is_integer)
** (CompileError) iex:21: undefined function is_integer/0
(stdlib) lists.erl:1354: :lists.mapfoldl/3
(stdlib) lists.erl:1355: :lists.mapfoldl/3
Run Code Online (Sandbox Code Playgroud)
是is_integer不是函数?从错误上看是这样的。我们在mapfoldl那里看到的是什么?
我在 Ecto 模型中有几个字段,我想为其插入 a) 默认值 b) 在我进行插入时生成值。我怎样才能做到这一点?在“变更集”中,我应该在哪个函数中执行此操作?
我的一项服务与速率受限的外部 API 通信,因此我想确保每 10 秒发送不超过 1 个调用。
我天真的方法是拥有一个长时间运行的 API 服务,并在每次调用后超时:
def handle_cast({:call_api, data}, state) do
send_to_external_api(data)
:timer.sleep(10000)
{:noreply, state}
end
Run Code Online (Sandbox Code Playgroud)
我不确定是否有适当的方法来做到这一点。
在使用网络协议(http、ftp 等)这个术语后,我对它在 Elixir 中的用法感到困惑。例如,有对 Enum 模块和 Enumerable Protocol 的引用。Elixir 文档说Protocols are a mechanism to achieve polymorphism in Elixir。
它们不只是具有一组方法/功能的模块吗?有什么区别吗?
如何测试以下代码?
["one", "two", "three"]) |> Enum.each(&IO.puts(&1))
one
two
three
:ok
Run Code Online (Sandbox Code Playgroud)
我的测试目前看起来像这样,但失败了,因为IO.puts返回:ok而不是字符串,并且可能不包括完整字符串中的换行符。
assert ["one", "two", "three"]) |> Enum.each(&IO.puts(&1)) == """
one
two
three
"""
Run Code Online (Sandbox Code Playgroud)
也许IO.puts是这个用例的错误功能。如果是这样,我可以使用什么替代方案?
提前致谢。
我需要找到 Ecto 检索到的数据库时间与当前时间(UTC)之间的分钟数差异。据我所知,如果不使用诸如 Timex 之类的第三方库,在 Elixir 上的计时操作并不是微不足道的。但是,我想避免使用第三方依赖项。那么如何找到时差呢?我知道我可以通过 获取当前时间DateTime.utc_now(),但是接下来如何从数据库中减去日期时间,这是Ecto.DateTime格式?
为什么会失败:
%Partner{} |> cast(%{id: 123}, [:id]) |> delete
Run Code Online (Sandbox Code Playgroud)
用Ecto.NoPrimaryKeyValueError? 我正在明确设置主键?