有没有人知道:host在每次请求时动态更改Phoenix应用程序端点的方法?
特别是为了支持单个phoenix app上的多个域,我想根据连接对象中的主机更改端点中的主机.
我正在尝试一些事情
conn = Map.get_and_update(conn.private.phoenix_endpoint[:url], :host, fn (_) -> "ll.com" end)
Run Code Online (Sandbox Code Playgroud)
要么
Keyword.put(conn.private.phoenix_endpoint.config(:url), :host, conn.host)
Run Code Online (Sandbox Code Playgroud)
但我不太正确.
我正在制作一个多站点应用程序.我想在测试控制器之前在连接上设置请求主机.在Rails中我们可以使用
before :each do
request.env["HTTP_REFERER"] = '/'
end
Run Code Online (Sandbox Code Playgroud)
有人可以建议如何在凤凰城做同样的事情吗?
编辑1:我可以使用设置主机
conn |> put_req_header("host", "abc.com"),但这不会更改对象host中的conn属性.它仍然指向"www.example.com"
编辑2:我也试过了
test "creates resource and redirects when data is valid", %{conn: _conn} do
struct_url = %{Myapp.Endpoint.struct_url | host: "abc.com"}
conn = post(conn, registration_url(struct_url, :create, user: @valid_attrs))
assert redirected_to(conn) == "/"
end
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
$ mix test test/controllers/registration_controller_test.exs 1) test creates resource and redirects when data is valid (Myapp.RegistrationControllerTest)
test/controllers/registration_controller_test.exs:14
** (RuntimeError) expected action/2 to return a Plug.Conn, all plugs must …Run Code Online (Sandbox Code Playgroud) 我在Windows上,正在尝试安装bcrypt_elixir模块。
我收到以下错误:
$ mix phx.server
==> bcrypt_elixir
could not compile dependency :bcrypt_elixir, "mix compile" failed. You can recompile this dependency with "mix deps.compile bcrypt_elixir", update it with "mix deps.update bcrypt_elixir" or clean it with "mix deps.clean bcrypt_elixir"
** (Mix) "nmake" not found in the path. If you have set the MAKE environment variable,
please make sure it is correct.
Run Code Online (Sandbox Code Playgroud)
这是错误的终端屏幕截图:
这是我的deps功能mix.exs:
defp deps do
[
{:phoenix, "~> 1.3.0"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.2"},
{:postgrex, ">= …Run Code Online (Sandbox Code Playgroud) 我想通过amqp从我的elixir phoenix应用程序中使用rabbitMQ.我在官方网站上关注了教程,但在此期间mix.deps compile,我收到一个错误:
include/amqp_gen_consumer_spec.hrl:30: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:31: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:32: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:34: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:35: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:36: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:37: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:38: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:39: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:42: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:30: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:31: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:32: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:34: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:35: syntax error …Run Code Online (Sandbox Code Playgroud) 我正在尝试在应用程序中实现不同的语言.所以我所做的就是在db中的Session中创建lang变量,它保留当前选择的语言.
问题是我正在通过更新操作调用和更新值:
def update(conn, %{"id" => id, "session" => session_params}) do
session = Repo.get!(Session, id)
changeset = Session.changeset(session, session_params)
case Repo.update(changeset) do
{:ok, _session} ->
conn
|> put_flash(:info, "Session updated successfully.")
|> redirect(to: page_path(conn, :tableshow))
{:error, changeset} ->
render(conn, "edit.html", session: session, changeset: changeset)
end
end
Run Code Online (Sandbox Code Playgroud)
,它将其重定向到特定路径(此处:page_path).我的问题:一旦调用动作,是否可以获取当前路径并重定向到它?那么,当你改变语言时,它不仅仅是将你重定向到一个特定的页面,而只是重新加载当前页面,在那里调用了动作?语言选择器在每个页面的标题中.所以我希望页面只是重新加载.任何建议?
附加信息:我正在调用app.html.eex中的操作
<%= render Pos1.SessionView, "session_en.html", changeset: @changesetlang, action: session_path(@conn, :update, @session) %>
Run Code Online (Sandbox Code Playgroud)
其中session_en.html是:
<%= form_for @changeset, @action, fn f -> %>
<%= hidden_input f, :lang, value: "1" %>
<%= submit "EN", class: "btn …Run Code Online (Sandbox Code Playgroud) 我正在使用Elixir Channels编写一个应用程序来处理实时事件.我知道每个客户端将打开1个套接字,并且可以在其上复用多个通道.所以我的应用程序是一个聊天应用程序,用户是多个群聊的一部分.我有一个名为MessageChannel的Phoenix Channel,其中join方法将处理动态主题.
def join("groups:" <> group_id, payload, socket) do
....
Run Code Online (Sandbox Code Playgroud)
假设John加入群组/主题A和B而Bob只加入群组/主题B.当john向群组/主题A发送消息时,广播!/ 3也会将该消息发送给Bob太正确了吗?因为handle_in没有发送消息的主题/组的上下文.
如何处理它以便Bob不会收到发送给A组的事件.我设计得对吗?
sockets elixir elixir-framework phoenix-framework phoenix-channels
我想比较两个技能列表,以提供一个分数出现在另一个列表中的百分比分数:
user_skills = [
%{name: "Elixir"},
%{name: "Python"}
]
project_skills = [
%{name: "Elixir"},
%{name: "Erlang"},
%{name: "Ruby"}
]
Run Code Online (Sandbox Code Playgroud)
user_skills出现的百分比是project_skills多少?我们想要的是的结果50%。
所以我试图在URL中传递多个参数来插件.这是我用于测试的URL:
http://localhost:4000/uid=ToddFlanders&pwd=MyTestPword
Run Code Online (Sandbox Code Playgroud)
这是代码:
defmodule Sci do
@userid "uid"
@password "pwd"
import Plug.Conn
import Plug.Conn.Utils
use Plug.Router
plug :match
plug :dispatch
get "/:args" do
%{@userid => usr} = params(args)
%{@password => pass} = params(args)
send_resp(conn, 200, "Hello #{usr}. Your password is #{pass}")
end
match _ do
send_resp(conn, 404, "oops")
end
def start do
Plug.Adapters.Cowboy.http Sci, [], port: 4000
end
def stop do
Plug.Adapters.Cowboy.shutdown Sci.HTTP
end
end
Run Code Online (Sandbox Code Playgroud)
如果我只传递一个参数(uid或pwd),它匹配正常.如果我删除?查询字符串前面的它失败 - 抛出异常.
我也试过这个:
get "/:args" do
%{@userid => usr, @password => pass} …Run Code Online (Sandbox Code Playgroud) 我正在按照本教程添加一个postgrex扩展到config.exs该extensions字段.但是现在这是添加postgrex扩展名的一种不推荐使用的方法,我们现在应该使用该type字段而不是extensions字段.我正在关注geo库github页面上的代码,添加扩展名:
config.exs
Postgrex.Types.define(MyApp.PostgresTypes,
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Poison)
use Mix.Config
config :api, Api.Repo,
types: MyApp.PostgresTypes,
adapter: Ecto.Adapters.Postgres,
database: "api_repo",
username: "postgres",
password: "postgres",
hostname: "localhost",
web_port: String.to_integer(System.get_env("PORT") || "4000"),
timeout: 60_000,
pool_timeout: 60_000
config :api, ecto_repos: [Api.Repo]
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
bash-3.2$ mix ecto.migrate
** (Mix.Config.LoadError) could not load config config/config.exs
** (UndefinedFunctionError) function Ecto.Adapters.Postgres.extensions/0 is undefined (module Ecto.Adapt
ers.Postgres is not available)
Ecto.Adapters.Postgres.extensions()
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(stdlib) erl_eval.erl:470: :erl_eval.expr/5
(stdlib) …Run Code Online (Sandbox Code Playgroud) 在Elixir中是否有任何实用程序函数,我想根据索引和大小从数组中获取子列表?
枚举实用程序不提供此功能
arr = [1,2,3,4,5,6,7]
from=2
size=3
res = sublist(arr,from,size)
#res should return [3,4,5]
Run Code Online (Sandbox Code Playgroud) elixir ×10
elixir-framework ×10
cygwin ×1
ecto ×1
elixir-mix ×1
linux ×1
list ×1
postgresql ×1
postgrex ×1
rabbitmq ×1
sockets ×1