gpt4 book ai didi

phoenix-framework - 在Elixir/Phoenix中渲染 “OK”的最简单方法是什么?

转载 作者:行者123 更新时间:2023-12-03 13:47:46 25 4
gpt4 key购买 nike

在Rails中,您可以直接渲染文本,例如render :text => 'OK'
Elixir / Phoenix中是否有快捷方式可以直接渲染文本,而无需定义模板或布局?

我发现的最短方法是:

  defmodule MyApp.PageController do
use MyApp.Web, :controller

def index(conn, _params) do
# the file ok.html.eex contains just the string OK
render conn, "ok.html", layout: false
end
end

有没有一种更短的方式来呈现“OK”,而不必提供模板文件“ok.html”?

最佳答案

http://www.phoenixframework.org/docs/controllers:

Rendering

Controllers have several ways of rendering content. The simplest is to render some plain text using the text/2 function which Phoenix provides.

Let's say we have a show action which receives an id from the params map, and all we want to do is return some text with the id. For that, we could do the following.

def show(conn, %{"id" => id}) do
text conn, "Showing id #{id}"
end

关于phoenix-framework - 在Elixir/Phoenix中渲染 “OK”的最简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38601617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com