下面的命令在生产模式下运行phoenix.server,并作为部署phoenix的命令给出.
MIX_ENV=prod PORT=4001 iex -S mix phoenix.server
Run Code Online (Sandbox Code Playgroud)
但是,上面的命令以交互方式运行服务器并关闭终端,阻止phoenix.server运行.如何让phoenix.server在后台运行?
我正在尝试在Phoenix应用程序中使用自定义字体.我已将它们放在priv/static/fonts目录中,并在web/templates/layout/app.html.eex模板中正确创建并加载了css文件,但它们并未由Phoenix Server提供服务.
/Users/Psycho/code/elixir/my_app/
? priv/
? repo/
? static/
? css/
? fonts/
? walsheim/
gt-walsheim-light-web.svg
gt-walsheim-light-web.eot
gt-walsheim-light-web.ttf
gt-walsheim-light-web.woff
Run Code Online (Sandbox Code Playgroud)
用于获取字体的css文件:
// my_app/priv/css/fonts.css
@font-face {
font-family: "Walsheim";
font-style: normal;
font-weight: 300;
src:
url("/fonts/walsheim/gt-walsheim-light-web.eot?#iefix") format("embedded-opentype"),
url("/fonts/walsheim/gt-walsheim-light-web.woff") format("woff"),
url("/fonts/walsheim/gt-walsheim-light-web.ttf") format("truetype"),
url("/fonts/walsheim/gt-walsheim-light-web.svg#Walsheim") format("svg");
}
Run Code Online (Sandbox Code Playgroud) 我是Elixir的新手,尝试将一个Rails API作为学习项目移植到Phoenix.
我有一个Postgres时间字段,我已添加到Ecto方案中:
field :start_time, Ecto.Time
Run Code Online (Sandbox Code Playgroud)
问题:我想输出一个12小时格式化版本的时间,如16:30作为字符串:例如,下午4:30.我一直无法找到一种简单/标准的方法来做到这一点.
这是我最接近解决方案的:
def format_time(time) do
{:ok, {hours,minutes,y, z}} = Ecto.Time.dump(time)
{hour, ampm} = Timex.Time.to_12hour_clock(hours)
"#{hour}:#{minutes}#{ampm}"
end
Run Code Online (Sandbox Code Playgroud)
对于我认为已经具有更简洁和标准的实现的东西来说,这似乎是一个荒谬而荒谬的长代码; 另外它有输出2:0pm而不是下午2:00的问题 - 用尾随零格式化0也是我正在处理的长而复杂的代码片段 - 此时我开始觉得事情正在发生偏离轨道.
建议赞赏!
defmodule UnixCommands do
alias Porcelain.Result
def run(command, *opts) do
%Result{out: output, status: _} = Porcelain.exec(command, [opts])
IO.puts output
end
end
Run Code Online (Sandbox Code Playgroud)
在Elixir中是否有等效的splat运算符,例如*opts?是否有办法将多个选项而不是选项列表作为参数传递给exec函数?
我希望添加其他布局参数,如@inner布局.例如@title,<title>@title</title>用于各个页面的onload javascript的区域.
window.onload = function () {
@onload_js
}
Run Code Online (Sandbox Code Playgroud)
这些是在布局中设置的,所以我不确定在Phoenix中处理这些的最佳方法.感谢:D.
是否可以在现有结构中设置值?我在谈论将现有结构传递给函数并设置结构"名称"值(例如)的想法?
我有什么:main.exs
Code.require_file("user.exs") # Requiring in module
person1 = User.constructor("Name") # Making a new user
IO.write inspect person1
Run Code Online (Sandbox Code Playgroud)
user.exs
defmodule User do
defstruct [name: ""]
def constructor(name) do
%User{name: name}
end
end
Run Code Online (Sandbox Code Playgroud)
有什么办法让这个想法有效吗?
def setName(struct, newName) do
struct.name = newName
end
Run Code Online (Sandbox Code Playgroud)
谢谢
今天,我经常尝试在我的Phoenix应用程序中混合使用ecto.migrate,并且出乎意料地发现了以下错误:
warning: could not find repositories for application :adah.
You can avoid this warning by passing the -r flag or by setting the
repositories managed by this application in your config files:
config :adah, ecto_repos: [...]
The configuration may be an empty list if it does not define any repo.
** (Protocol.UndefinedError) protocol Enumerable not implemented for :ok
(elixir) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) lib/enum.ex:116: Enumerable.reduce/3
(elixir) lib/enum.ex:1486: Enum.reduce/3
(elixir) lib/enum.ex:609: Enum.each/2
(mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
Run Code Online (Sandbox Code Playgroud)
我的代表是:
phoenix_ecto: 3.0.0-rc.0
ecto: 2.0.0-rc.0 …Run Code Online (Sandbox Code Playgroud) 我有一个用Elixir Phoenix框架工作的网站.该网站在开发和生产模式下运行良好.
当凤凰服务器在开发模式下运行,我没有问题renewingLet的加密证书,但是当完全相同的应用程序在PROD模式下运行,我不断尝试续订时,得到允许误差.请注意,我正在谈论完全相同的应用程序,在同一个 FreeBSD服务器上,由同一个用户执行- 两个命令都没有sudo.该唯一的区别是MIX_ENV=prod
我还注意到在prod模式下,凤凰服务器在Letsencrypt尝试访问我的priv/static/.well-known/acme-challenge/(some-unique-string)基本设置为phoenix + letsencrypt 时记录404错误在此博客文章中有详细说明
问题是:phoenix服务器如何在`prod'和'dev'模式之间区别对待目录/文件权限?
更新:
伙计们,因为LetsEncrypt和凤凰框架迅速发展,我上面列出的问题已不再是一个问题,如果你正在使用从LetsEncrypt和凤凰1.2.0最新cerbot
但这不是原始问题的答案.
freebsd elixir web-deployment phoenix-framework lets-encrypt
使用以下步骤使用Edeliver&Distillery将我们的应用程序成功部署到虚拟机后:https: //github.com/dwyl/learn-phoenix-framework/blob/master/production-deployment.md
该应用程序运行:http://52.232.127.28/

但是当我们试图访问"帖子"路线时:http://52.232.127.28/posts
我们看到internal server error:

作为一个凤凰诺布,我不知道如何调试Prod中的日志......
我们如何在虚拟机上看到这些日志?日志在哪里,我们可以tail记录日志吗?
我希望能够在运行时动态更改计算管道,但似乎GenStage要求在编译时通过subscribe_to: [...]机制定义计算图.有没有办法创建动态计算图?例如,在下面,我想在运行时切换管道图中的"减7"和"减4"顶点.
这可能使用GenStage吗?我可能会有非常复杂的流水线,因此我需要一种能够以复杂方式扩展到更改图形的解决方案,而不是像特殊解决方案那样,例如,将整数参数化为减法.我希望能够添加或删除整个子树,在子树之间切换,并将节点添加到图形中,包括将它们拼接到任何子树的中间,包括主树.
这是最初的制作人:
defmodule GenstageTest.Producer do
use GenStage
def start_link(initial \\ 1) do
GenStage.start_link(__MODULE__, initial, name: __MODULE__)
end
def init(counter), do: {:producer, counter}
def handle_demand(demand, state) do
events = Enum.to_list(state..(state + demand - 1))
{:noreply, events, state + demand}
end
end
Run Code Online (Sandbox Code Playgroud)
这是producer_consumers之一:
defmodule GenstageTest.PcTimesFive do
use GenStage
def start_link do
GenStage.start_link(__MODULE__, :state_doesnt_matter, name: __MODULE__)
end
def init(state) do
{:producer_consumer, state, subscribe_to: [GenstageTest.PcAddOne]}
end
def handle_events(events, _from, state) do
numbers =
events
|> Enum.map(&(&1 * 5))
{:noreply, …Run Code Online (Sandbox Code Playgroud)