我目前正在寻找在页面处于活动状态时添加CSS类.凤凰目前最好的办法是什么?这个案子有帮助吗?
def active(option, conn) do
if option == conn.request_path do
" class=\"active\""
else
""
end
end
Run Code Online (Sandbox Code Playgroud)
在模板中:
<%= "contact" |> active(@conn) |> raw %>
Run Code Online (Sandbox Code Playgroud) 我有一个测试需要在测试之前将user_id设置为session,因为此操作需要知道current_user.
setup do
%User{
id: 123456,
username: "lcp",
email: "abc@gmail.com",
password: Comeonin.Bcrypt.hashpwsalt("password")
} |> Repo.insert
{:ok, user: Repo.get(User, 123456) }
end
test "POST /posts", context do
# conn = conn()
# |> put_session(:user_id, context[:user].id)
# |> post("/posts", %{ post: %{ title: "title", body: "body" } })
# assert get_flash(conn, :info) == "Post created successfully."
# updated to =>
conn = conn()
|> Map.put(:secret_key_base, String.duplicate("abcdefgh", 8))
|> Plug.Session.call(@session)
|> Plug.Conn.fetch_session
|> put_session(:user_id, context[:user].id)
|> post("/posts", %{ post: %{ title: "title", body: …Run Code Online (Sandbox Code Playgroud) 我开始玩Ecto试图理解它.正如预期的那样,我搞砸了(使用用户模型),我在运行迁移时遇到错误:
(Postgrex.Error) ERROR (duplicate_table): relation "users" already exists
Run Code Online (Sandbox Code Playgroud)
现在,我想使用shell/PgAdmin III清理数据库,以便我可以修复我的模型并再次运行迁移.我已经设置了PgAdmin,但我无法看到任何"用户"表...这样做的最佳方式是什么(使用Ecto,PostgreSQL shell还是PgAdmin)?
Rails.root凤凰城有类似的东西吗?假设我想在Phoenix应用程序中使用配置文件.查找脚本中使用的文件和路径的约定是什么?
如果您的应用程序/ api在vanilla Phoenix应用程序中启动,您是否会将要运行的代码放入?假设我想确保创建一些mnesia表或配置我的记录器后端.另一件事是运行时配置.他们在文档中提到它,但我不清楚在哪里定义/更改运行时配置.
Endpoint.ex 看起来像是一个完成初始配置的地方,但通过查看文档,我找不到任何允许我在启动时只运行一次代码的回调.
mix phoenix.gen.html生成一堆文件.如何撤消这一代?还是我必须手工完成?
我正在尝试在屏幕上显示一个表单.但是当我尝试启动服务器时,我一直收到此错误.locations_controller.ex ==
** (CompileError) web/controllers/locations_controller.ex:5: Locations.__struct__/1 is undefined, cannot expand struct Locations.顺便说一下,我是elixir的新手,所以我可能做了一些非常明显错误的事情.
这是我的代码:
def new(conn, _params) do
changeset = Locations.changeset(%Locations{})
render conn, "new.html", changeset: changeset
end
def create(conn, %{"locations" => %{ "start" => start, "end" => finish }}) do
changeset = %AwesomeLunch.Locations{start: start, end: finish}
Repo.insert(changeset)
redirect conn, to: locations_path(conn, :index)
end
Run Code Online (Sandbox Code Playgroud)
<h1>Hey There</h1>
<%= form_for @changeset, locations_path(@conn, :create), fn f -> %>
<label>
Start: <%= text_input f, :start %>
</label>
<label>
End: <%= text_input f, …Run Code Online (Sandbox Code Playgroud) 我有凤凰1.3 +苦艾酒的问题.
我试试这段代码:
schema "urls" do
field :path, :string
timestamps()
end
object :url do
field :id, :id
field :path, :string
field :inserted_at, :datetime
end
Run Code Online (Sandbox Code Playgroud)
它可以使用id,path但它失败inserted_at了:
Inserted_at :datetime is not defined in your schema.
Types must exist if referenced.
lib/absinthe/schema.ex:230: Absinthe.Schema.__after_compile__/2
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:121: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1
Run Code Online (Sandbox Code Playgroud)