elixir

Could not compile dependency :idna after adding “timex” dependency.

天大地大妈咪最大 提交于 2019-12-12 19:48:31
问题 After adding "timex" dependency I am facing this issue here is the error ===> Command bare not found ** (Mix) Could not compile dependency :idna, "/usr/bin/rebar3 bare compile --paths "phoenix/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile idna", update it with "mix deps.update idna" or clean it with "mix deps.clean idna" 来源: https://stackoverflow.com/questions/36838824/could-not-compile-dependency-idna-after-adding-timex-dependency

Automatic update of parent record updated_at field (Elixir-Ecto)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 19:06:04
问题 Suppose I have two models: Parent and Child. If a Child record is updated, is there an option to update the associated Parent record timestamp automatically? 回答1: There are a couple ways you can do it. One of them requires Ecto master (soon to be Ecto v2.0) and is by simply updating the parent directly: # Assuming a child_changeset with the parent loaded child_changset = Ecto.Changeset.put_assoc(child_changeset, :parent, %{updated_at: Ecto.DateTime.utc}) Now, when the child is persisted, it

Ecto warning with embedded model

余生长醉 提交于 2019-12-12 16:33:47
问题 I get this warning when casting warning: casting embeds with cast/4 is deprecated, please use cast_embed/3 instead I have the model Organization defmodule Bonsai.Organization do use Bonsai.Web, :model alias Bonsai.OrganizationSettings schema "organizations" do field :name, :string field :currency, :string field :tenant, :string field :info, :map, default: %{} embeds_one :settings, OrganizationSettings, on_replace: :delete timestamps end @required_fields ~w(name currency tenant) @optional

Elixir application with multiple/dynamic config files

家住魔仙堡 提交于 2019-12-12 15:37:58
问题 I have an elixir application, an application server, that would benefit from start up parameters. This application uses an ecto repository, so I can store an app server's configuration there, but I'd still need a configuration key for what to retrieve from the db. Presently I've been using config.exs for the server application (the whole application is an umbrella project), but obviously this only handles one static configuration. My question is: Can I use mix to specify what config file I'd

How to show all records of a model in Phoenix select field

不羁岁月 提交于 2019-12-12 15:07:01
问题 I have following models... Page Category i have following code in new action of page_controller.ex def new(conn, _params) do changeset = Page.changeset(%Page{}) categories = Repo.all(Category) render(conn, "new.html", changeset: changeset, categories: categories) end I have following code for select field in page/new.html.eex <div class="form-group"> <%= label f, :category_id, "Parent", class: "control-label" %> <%= select f, :category_id, @categories ,class: "form-control" %> </div> It

Elixir Phoenix inlining css for sending emails

早过忘川 提交于 2019-12-12 14:19:15
问题 I am sending emails using the mailgun library in Phoenix. Turns out that when i look at the email in my gmail account, it has been stripped off of all the css classes and the link to external css files. Mailgun suggests using a css inline library http://blog.mailgun.com/transactional-html-email-templates/ Tried search a lot, but could not find a css inline library for Phoenix/Elixir like the premailer gem in Ruby. Does anyone know of a way to achieve this? 回答1: I just released Smoothie, an

Why does Ecto's `cast` not convert an integer to a string?

岁酱吖の 提交于 2019-12-12 13:47:06
问题 I have an Ecto schema that includes field :owned_by_id, :string . I declared the field a string because I need to support values like "abc123" as well as values like "123". The docs for cast/3 say: The second argument is a map of params that are cast according to the type information from data . In my module, I define changeset like: def changeset(struct, params \\ %{}) do cast(struct, params, [:owned_by_id]) end When I do this: MyModule.changeset(%MyModule{}, %{owned_by_id: 1}) ... I would

Display table data from RethinkDB in Phoenix Framework

不打扰是莪最后的温柔 提交于 2019-12-12 12:52:28
问题 I'm attempting to display data from my databases in RethinkDB (using the rethinkdb-elixir package from Hamiltop https://github.com/hamiltop/rethinkdb-elixir) in Phoenix. I'm relatively new to both, but I already managed to insert two tables and some data into those tables. I know this because I checked it through RethinkDB's web GUI. Now I want to display table data in an html page of my project. I've reduced the errors to one: protocol Phoenix.HTML.Safe not implemented for %RethinkDB

Elixir, using function from another module

笑着哭i 提交于 2019-12-12 12:40:08
问题 I am extremly new to the programming and to the elixir. So I am very exited to learn as much as i can. But ive got a trouble. I looking the way how to use my functions in another module. I am building the web-server wich stores the key-value maps in the memory. To keep the maps temporary Ive decided to use Agent. Here is the part of my code: defmodule Storage do use Agent def start_link do Agent.start_link(fn -> %{} end, name: :tmp_storage) end def set(key, value) do Agent.update(:tmp_storage

Elixir: Resume code execution after reaching IEx.pry

烂漫一生 提交于 2019-12-12 12:24:20
问题 In ruby Ctrl - d allows to resume the execution of the code after reaching a binding.pry . What is the equivalent in Elixir for IEx.pry ? 回答1: As documented in IEx.pry/0, you can call respawn to resume the execution. This is useful for debugging a particular chunk of code when executed by a particular process. The process becomes the evaluator of IEx commands and is temporarily changed to have a custom group leader. Those values are reverted by calling IEx.Helpers.respawn/0 , which starts a