标签: phoenix-framework

Ubuntu上的新凤凰项目找不到[错误]后端端口:: inotifywait

我创建了一个新的凤凰项目,当我运行mix phoenix.server时,我得到了

[error]后端端口未找到:: inotifywait

在我的控制台中红色.这看起来很危险,因为我还没有真正做过任何事情,所以看起来应该是有用的东西.

elixir phoenix-framework

12
推荐指数
1
解决办法
1447
查看次数

"无法开始测试交易,因为我们已经在一个内部"

我遵循了本教程,我的简单测试总是因为这个错误而失败

1) test /index returns a list of contacts (WorldNote.ChatsControllerTest)                                             
     test/controllers/chats_controller_test.exs:16                                                                      
     ** (RuntimeError) cannot begin test transaction because we are already inside one                                  
     stacktrace:                                                                                                        
       (ecto) lib/ecto/adapters/sql.ex:321: anonymous fn/6 in Ecto.Adapters.SQL.start_test_transaction/3                
       (ecto) lib/ecto/adapters/sql.ex:615: Ecto.Adapters.SQL.pool_transaction/4                                        
       (ecto) lib/ecto/adapters/sql.ex:314: Ecto.Adapters.SQL.start_test_transaction/3                                  
       test/controllers/chats_controller_test.exs:9: WorldNote.ChatsControllerTest.__ex_unit_setup_0/1                  
       test/controllers/chats_controller_test.exs:1: WorldNote.ChatsControllerTest.__ex_unit__/2    
Run Code Online (Sandbox Code Playgroud)

代码很简单

defmodule WorldNote.ChatsControllerTest do
  use ExUnit.Case, async: false
  use Plug.Test
  alias WorldNote.Chats
  alias WorldNote.Repo
  alias Ecto.Adapters.SQL

  setup do
    SQL.begin_test_transaction(Repo)

    on_exit fn ->
      SQL.rollback_test_transaction(Repo)
    end
  end

  test "/index returns a list of contacts" do
    contacts_as_json =
      %Chats{fbid: 1234567890, latitude: …
Run Code Online (Sandbox Code Playgroud)

elixir ecto phoenix-framework

12
推荐指数
1
解决办法
760
查看次数

独特的索引约束在Phoenix应用程序中不起作用

在我的凤凰应用程序中,我的用户模型如下:

defmodule MyApp.User do
  use MyApp.Web, :model

  schema "users" do
    field :username, :string, unique: true
    field :email, :string, unique: true
    field :crypted_password, :string
    field :password, :string, virtual: true

    timestamps
  end

  @required_fields ~w(email password username)
  @optional_fields ~w()

  @doc """
  Creates a changeset based on the `model` and `params`.

  If no params are provided, an invalid changeset is returned
  with no validation performed.
  """
  def changeset(model, params \\ :empty) do
    model
    |> cast(params, @required_fields, @optional_fields)
    |> unique_constraint(:email)
    |> unique_constraint(:username)
    |> validate_format(:email, ~r/@/) …
Run Code Online (Sandbox Code Playgroud)

elixir phoenix-framework

12
推荐指数
1
解决办法
3991
查看次数

Iex撬开一步一步走?

我想使用IEx.pry逐步使用我的elixir代码,比如ruby中的byebug或Java中的调试点.我试着在这里查看文档:https://github.com/elixir-lang/elixir/blob/4f68c4f10502e0f54a21093bb9a33957e63a9ac4/lib/iex/lib/iex.ex 但没有找到任何内容.谁有人建议这样做的方法?

elixir phoenix-framework iex

12
推荐指数
1
解决办法
2245
查看次数

如何在我的模型文件中使用Repo模块

在我的Tag模型代码中

schema "tags" do
  field :name, :string
  field :parent, :integer # parent tag id
  timestamps
end

def add_error_when_not_exists_tag_id(changeset, params) do
  tags = Repo.all(Tag)
  is_exists_tag_id = Enum.reduce(tags, fn(x, acc) -> acc || (x.id === params.parent) end)
  if is_exists_tag_id, do: changeset, else: add_error(changeset, :parent, "not exists parent!")
end
Run Code Online (Sandbox Code Playgroud)

上面的代码导致下面的错误.

(UndefinedFunctionError) undefined function: Repo.all/1 (module Repo is not available)
Run Code Online (Sandbox Code Playgroud)

我可以修复错误吗?

Tag模型是嵌套标签模型.

标签可以有父标签.


最终代码如下.这很好.

在模型中

def add_error_when_not_exists_tag_id(changeset, params, tags) do
  is_exists_tag_id = Enum.reduce(tags, false, fn(x, acc) -> acc || (Integer.to_string(x.id) …
Run Code Online (Sandbox Code Playgroud)

elixir ecto phoenix-framework

12
推荐指数
1
解决办法
4857
查看次数

删除链接不工作凤凰

我使用Phoenix内置的gen.HTML生成一个简单的视图,但它不起作用

<%= link "Delete", to: event_path(@conn, :delete, event), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %>
Run Code Online (Sandbox Code Playgroud)

在页面上它看起来像是假设,但它只是附加#到地址

生成结构:

<form action="/event/1" class="link" method="post">
   <input name="_method" type="hidden" value="delete">
   <input name="_csrf_token" type="hidden" value="BwUSGQcDO1MwPzw0HBgqLnshHn8HNgAAnCTjuMt0viFshobX4XM/dQ==">
   <a class="btn btn-danger btn-xs" data-confirm="Are you sure?" data-submit="parent" href="#">Delete</a>
</form>
Run Code Online (Sandbox Code Playgroud)

我错过了js导入的排序吗?我也可以通过浏览器下载:

//This is being downloaded as phoenix_html.js
// Although ^=parent is not technically correct,
// we need to use it in order to get IE8 support.
var elements = document.querySelectorAll('[data-submit^=parent]')
var len = elements.length

for (var …
Run Code Online (Sandbox Code Playgroud)

elixir phoenix-framework

12
推荐指数
3
解决办法
4259
查看次数

UndefinedFunctionError phoenix elixir新项目

随着凤凰城的全新安装,我试图触发一个新项目,当我尝试运行服务器时,我遇到了:

Unchecked dependencies for environment dev:
 * gettext (Hex package)
  the dependency is not available, run "mix deps.get"
 * phoenix_live_reload (Hex package)
  the dependency is not available, run "mix deps.get"
 * cowboy (Hex package)
 * List item
...
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时,mix deps.get我得到:

Running dependency resolution
** (UndefinedFunctionError) undefined function Access.Map.get_and_update!/3 (module Access.Map is not available)
    Access.Map.get_and_update!(%Mix.Dep{app: :cowboy, deps: [], extra: [], from: "/Users/victoriawagman/Dropbox/Hemsidor/digitalocean/hello_phoenix/mix.exs", manager: nil, opts: [hex: :cowboy, build: "/Users/victoriawagman/Dropbox/Hemsidor/digitalocean/hello_phoenix/_build/dev/lib/cowboy", dest: "/Users/victoriawagman/Dropbox/Hemsidor/digitalocean/hello_phoenix/deps/cowboy"], requirement: "~> 1.0", scm: Hex.SCM, status: {:unavailable, "/Users/victoriawagman/Dropbox/Hemsidor/digitalocean/hello_phoenix/deps/cowboy"}, …
Run Code Online (Sandbox Code Playgroud)

elixir phoenix-framework

12
推荐指数
1
解决办法
1507
查看次数

如何在Phoenix中的通道上启用压缩?

我有一个凤凰频道推出了大约4KB的数据,很多都是高度重复的,并且想知道是否有办法打开该频道的压缩.

如果我正在使用凤凰控制器,它看起来相当简单,但我无法确定这是否可行或在某个地方为某个频道记录.

谢谢一堆.

elixir phoenix-framework

12
推荐指数
1
解决办法
931
查看次数

如何在凤凰中使用会话连接?

我有一个身份验证插件,我想测试我的控制器.问题是这个插头中的线路有

user_id = get_session(conn, :user_id)
Run Code Online (Sandbox Code Playgroud)

当我使用这种方法时,它总是零(我以前使用过脏黑客,但我不想再这样做了):

  @session  Plug.Session.init([
    store:            :cookie,
    key:              "_app",
    encryption_salt:  "secret",
    signing_salt:     "secret",
    encrypt:          false
  ])

user = MyApp.Factory.create(:user)

conn()
|> put_req_header("accept", "application/vnd.api+json")
|> put_req_header("content-type", "application/vnd.api+json")
|> Map.put(:secret_key_base, String.duplicate("abcdefgh", 8))
|> Plug.Session.call(@session)
|> fetch_session
|> put_session(:user_id, user.id)
Run Code Online (Sandbox Code Playgroud)

我正在使用此conn发送补丁请求,其会话user_id为nil.IO.puts conn在我的插件中的结果:

%Plug.Conn{adapter: {Plug.Adapters.Test.Conn, :...}, assigns: %{},
 before_send: [#Function<0.111117999/1 in Plug.Session.before_send/2>,
  #Function<0.110103833/1 in JaSerializer.ContentTypeNegotiation.set_content_type/2>,
  #Function<1.55011211/1 in Plug.Logger.call/2>,
  #Function<0.111117999/1 in Plug.Session.before_send/2>], body_params: %{},
 cookies: %{}, halted: false, host: "www.example.com", method: "PATCH",
 owner: #PID<0.349.0>,
 params: %{"data" => %{"attributes" => %{"action" …
Run Code Online (Sandbox Code Playgroud)

elixir phoenix-framework ex-unit

12
推荐指数
1
解决办法
2427
查看次数

我应该在哪里将用户上传的文件和图像存储在Phoenix/Elixir中?

我的应用程序的用户应该能够上传图像等文件.在哪个文件夹中,我应该保存这些文件?我对部署Elixir/Phoenix应用程序并不熟悉,但我不希望将这些文件包含在我部署应用程序时生成的输出打包文件中.换句话说,我不想以某种方式将上传的图像和文件静态嵌入到我的应用程序中.那么我应该在哪里存储它们?

elixir phoenix-framework

12
推荐指数
2
解决办法
2237
查看次数

标签 统计

elixir ×10

phoenix-framework ×10

ecto ×2

ex-unit ×1

iex ×1