phoenix-framework

How do interpolation fields in Ecto queries?

不问归期 提交于 2021-02-08 11:14:52
问题 The Ecto documentation shows how to do interpolation values. But I need dynamic fields in my queries. I have dozens of fields and write queries for each of them does not seem cohesive. defmodule Hedone.SearchController do use Hedone.Web, :controller alias Hedone.User def idade(conn, %{"idade+" => maior, "idade-" => menor, "campo" => campo}) do IO.inspect campo query = from u in User, where: u.campo > ^maior and u.campo < ^menor, select: u.name pesquisa = Repo.all query IO.inspect pesquisa

In Elixir, Phoenix, how to get session in other module as a module use Phoenix.Channel?

只谈情不闲聊 提交于 2021-02-04 18:39:25
问题 In Elixir and Phoenix, I can get session in Controller by Plug.Conn.get_session(conn, :id) So how to get session in other module as a module use Phoenix.Channel ? 回答1: Plug.Conn is not available in Phoenix.Channel. Channels rely on Phoenix.Socket instead and you can use Phoenix.Token for authentication. Here's a tutorial on how to authenticate channels in Phoenix. 来源: https://stackoverflow.com/questions/34446712/in-elixir-phoenix-how-to-get-session-in-other-module-as-a-module-use-phoenix-c

Location for a Phoenix helper in a hex package

僤鯓⒐⒋嵵緔 提交于 2021-01-29 09:45:54
问题 I created an alternative phx.gen.html which creates templates with TailwindCSS. It works fine. I'd like to share it by creating a Hex package phx_tailwind_generators . Here is what I have so fare: $ phx_tailwind_generators:main> tree . ├── README.md ├── lib │ ├── phx_tailwind_generators.ex ├── mix.exs ├── priv │ └── templates │ └── tailwind.gen.html │ ├── controller.ex │ ├── controller_test.exs │ ├── edit.html.eex │ ├── form.html.eex │ ├── index.html.eex │ ├── new.html.eex │ ├── show.html.eex

could not compile dependency :salty, “mix compile” failed

…衆ロ難τιáo~ 提交于 2021-01-28 11:54:09
问题 I am compiling my application with mix compile and there an error is occurring for the dependency salty . I have already added the dependency salty and libsodium . But still error is not resolved. this is my mix.exs file with all the dependencies. defp deps do [ {:poison, "~> 3.0", override: true}, {:syndicate, in_umbrella: true}, {:xarango, "~> 0.7.0"}, {:ecto, "~> 3.1"}, {:phoenix, "~> 1.4.0"}, {:gettext, "~> 0.11"}, {:cowboy, "~> 2.6"}, {:joken, "~> 2.0"}, {:ecto_sql, "~> 3.0"}, {:jason, "

Using fragment & group_by together with postgres & ecto?

假如想象 提交于 2021-01-28 09:33:49
问题 I'm struggling to get this to work with Postgres and Ecto. The query below works fine without the group_by, but I need to group on the fragment field, which it can't seem to see. Any idea what's wrong with it? def query_clicks do from(Click) |> select( [c], [ fragment("date_trunc('hour',?) as hour", c.inserted_at), c.link_id] ) |> group_by([c], c.hour) |> Repo.all end Result: iex(1)> recompile; Shortr.LinkContext.query_clicks [debug] QUERY ERROR source="clicks" db=1.2ms queue=4.9ms SELECT

Using fragment & group_by together with postgres & ecto?

删除回忆录丶 提交于 2021-01-28 09:30:46
问题 I'm struggling to get this to work with Postgres and Ecto. The query below works fine without the group_by, but I need to group on the fragment field, which it can't seem to see. Any idea what's wrong with it? def query_clicks do from(Click) |> select( [c], [ fragment("date_trunc('hour',?) as hour", c.inserted_at), c.link_id] ) |> group_by([c], c.hour) |> Repo.all end Result: iex(1)> recompile; Shortr.LinkContext.query_clicks [debug] QUERY ERROR source="clicks" db=1.2ms queue=4.9ms SELECT

In Elixir/Phoenix, after template change, “cannot define module MyApp.PageView because it is currently being defined”

时光总嘲笑我的痴心妄想 提交于 2021-01-28 03:50:49
问题 I just changed an image path in a template in my Phoenix app and reloaded the page. This error message appeared in the browser: CompilationError at GET / Showing console output == Compilation error on file web/views/page_view.ex == ** (CompileError) web/views/page_view.ex:1: cannot define module Youli.PageView because it is currently being defined in web/views/page_view.ex:1 (stdlib) erl_eval.erl:657: :erl_eval.do_apply/6 Running mix compile in the terminal made the problem go away, but isn't

Elixir comprehension returning a star character '*'

允我心安 提交于 2021-01-05 06:24:10
问题 I have a list of Persona models being returned in p.followings and I want to extract the followed_id field from this list of models into a separate list. p.followings returns... [ %Poaster.Personas.Following{ __meta__: #Ecto.Schema.Metadata<:loaded, "followings">, followed: %Poaster.Personas.Persona{ __meta__: #Ecto.Schema.Metadata<:loaded, "personas">, background_image_url: nil, bio: "ASDF", followings: #Ecto.Association.NotLoaded<association :followings is not loaded>, id: 42, inserted_at:

Why doesn't the file_input in the form on a Phoenix LiveView return a %Plug.Upload{}?

爱⌒轻易说出口 提交于 2020-12-30 07:58:25
问题 I have a form in a Phoenix LiveView that contains a file_input . I want to use it to allow a user to upload an image. I'm having trouble understanding what the form is sending to my backend, and what I can do with it. I expected a %Plug.Upload{} representation of the image file, as described in documentation, but instead I just get "[object File]" . Note that I am not backing the form with a changeset, because I am not using Ecto: <%= f = form_for :post, "#", phx_submit: :create_post, phx

Phoenix Framework - page titles per route

拥有回忆 提交于 2020-12-29 06:23:53
问题 In the Phoenix Framework is there a common technique for setting a page title based on a route/path. Or is this just a matter of calling assign(:page_title, "fred") at the right point inside my routed function? Update I ended up implementing a variation of @michalmuskala's solution. I pass up the action name instead of @view_template : <title><%= @view_module.title(action_name(@conn), assigns) %></title> Then in the view module the code looks like this: def title(:show, assigns), do: assigns