标签: phoenix-framework

从 Elixir 的视图中调用渲染部分

我正在和 Phoenix 一起学习 Elixir,但陷入了一个相当愚蠢的境地。我想通过以下方式从索引模板内部调用部分的渲染:

#index.html.slim

- for element_here  <- array_here do
  = render MyApp.SharedView, "_game.html.slim", element: element_here
Run Code Online (Sandbox Code Playgroud)

为此,我创建了一个名为 shared_view.ex 的视图,如下所示:

defmodule MyApp.SharedView do
  use MyApp.Web, :view
  def render("game", _assigns), do: "/shared/_game.html.slim"
end
Run Code Online (Sandbox Code Playgroud)

我预计它会经历循环渲染共享/_game.html.slim,我将其复制到此处:

.col-md-4.portfolio-item
  a href="#"
    img.img-responsive alt="" src="http://placehold.it/700x400" /
  h3
    a href="#"  Project Name
  p Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.
Run Code Online (Sandbox Code Playgroud)

但没有任何内容被渲染。我也没有收到错误。它只是渲染之前和之后的内容。

我不确定我在这里缺少什么。没有路线或控制器操作连接到“_game”部分,因为我认为它没有必要(我习惯了 Rails,它在那里以这种方式工作)。

rendering elixir phoenix-framework

0
推荐指数
1
解决办法
1176
查看次数

Elixir/Phoenix 在 ErrorView 上渲染 json

当路由不匹配时,我尝试发送 json。从error_view.ex,我认为错误首先出现:

def template_not_found(_template, assigns) do
  render "404.html", assigns
end
Run Code Online (Sandbox Code Playgroud)

但如果我将其更改为:

def template_not_found(_template, assigns) do
  %{message: "custom error"}
end
Run Code Online (Sandbox Code Playgroud)

它实际上并不发送 json ,而是返回 me no function clause matching in Phoenix.Template.HTML.encode_to_iodata!/1。我相信这是因为它需要发送一些 html。可以改成发送json吗?

我的路由器:

defmodule AppWeb.Router do
  use AppWeb, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/", AppWeb do
    pipe_through :browser # Use the default browser stack

    get "/", PageController, :index
  end

  scope …
Run Code Online (Sandbox Code Playgroud)

json elixir phoenix-framework

0
推荐指数
1
解决办法
1816
查看次数

Phoenix 1.3 闪光灯不显示

我的方法put_flash(conn)get_flash(conn)方法表现得很奇怪;当我使用重定向时,一切正常,但当我尝试添加flash_msg后面的控制器时,什么也没有显示。

看起来消息存储在:phoenix_flash而不是:plug_session; 知道那里出了什么问题吗?

  def index(conn, _params) do
    conn
    |> put_flash(:info, "Welcome : info")
    |> put_flash(:error, "Welcome : error")
    render conn, "index.html"
  end

private: %{EverlearnWeb.Router => {[], %{}}, 
:phoenix_action => :index,
:phoenix_controller => EverlearnWeb.PageController,
:phoenix_endpoint => EverlearnWeb.Endpoint,
:phoenix_flash => %{"error" => "Welcome : error", "info" => "Welcome : info"},
:phoenix_layout => {EverlearnWeb.LayoutView, :app},
:phoenix_pipelines => [:browser], :phoenix_router => EverlearnWeb.Router,
:phoenix_view => EverlearnWeb.PageView,
:plug_session => %{"_csrf_token" => "xxx",
 "phoenix_flash" => %{"info" => …
Run Code Online (Sandbox Code Playgroud)

elixir flash-message phoenix-framework

0
推荐指数
1
解决办法
1130
查看次数

在 Phoenix 路由器中使用不带 :id 的资源宏

默认情况下,宏会在路由末尾resources附加一个,用于对单个资源执行操作。/:id

但是,我遇到的情况是,用户必须始终登录才能对自己执行操作。我更喜欢:current_user从获取conn.assigns,而不是通过传入/显示 URL 中的任何参数。我知道我总能把路线一一写出来。我只是想知道是否有办法让resources生成这样的路径。

elixir phoenix-framework

0
推荐指数
1
解决办法
625
查看次数

在Phoenix中使用自定义SQL代码生成迁移

我想Ecto使用自定义SQL代码生成新的迁移,而不是使用提供的帮助程序.当前的mix生成器任务仅处理模型.

如何在迁移中编写原始SQL代码?

sql elixir ecto phoenix-framework

-1
推荐指数
1
解决办法
421
查看次数

使用elixir的Web应用程序框架选项?

elixir laguagem的Web应用程序框架有哪些选项?最近我在学习Phoenix(http://phoenixframework.org/),但我不确定它是最好的还是唯一的选择.

elixir phoenix-framework

-2
推荐指数
1
解决办法
183
查看次数

标签 统计

elixir ×6

phoenix-framework ×6

ecto ×1

flash-message ×1

json ×1

rendering ×1

sql ×1