elixir

Elixir ecto connect to an existing DB

此生再无相见时 提交于 2020-01-13 13:06:03
问题 After doing some research in the link below https://github.com/elixir-lang/ecto/tree/master/examples/simple I am a little confused about how to use ecto in elixir. There is always a schema declared like defmodule Weather do use Ecto.Model schema "weather" do field :city, :string field :temp_lo, :integer field :temp_hi, :integer field :prcp, :float, default: 0.0 timestamps end end and then in the 'Query' part def sample_query do query = from w in Weather, where: w.prcp > 0.0 or is_nil(w.prcp),

Elixir ecto connect to an existing DB

廉价感情. 提交于 2020-01-13 13:04:48
问题 After doing some research in the link below https://github.com/elixir-lang/ecto/tree/master/examples/simple I am a little confused about how to use ecto in elixir. There is always a schema declared like defmodule Weather do use Ecto.Model schema "weather" do field :city, :string field :temp_lo, :integer field :temp_hi, :integer field :prcp, :float, default: 0.0 timestamps end end and then in the 'Query' part def sample_query do query = from w in Weather, where: w.prcp > 0.0 or is_nil(w.prcp),

Elixir ecto connect to an existing DB

ⅰ亾dé卋堺 提交于 2020-01-13 13:04:21
问题 After doing some research in the link below https://github.com/elixir-lang/ecto/tree/master/examples/simple I am a little confused about how to use ecto in elixir. There is always a schema declared like defmodule Weather do use Ecto.Model schema "weather" do field :city, :string field :temp_lo, :integer field :temp_hi, :integer field :prcp, :float, default: 0.0 timestamps end end and then in the 'Query' part def sample_query do query = from w in Weather, where: w.prcp > 0.0 or is_nil(w.prcp),

Elixir ecto connect to an existing DB

老子叫甜甜 提交于 2020-01-13 13:04:13
问题 After doing some research in the link below https://github.com/elixir-lang/ecto/tree/master/examples/simple I am a little confused about how to use ecto in elixir. There is always a schema declared like defmodule Weather do use Ecto.Model schema "weather" do field :city, :string field :temp_lo, :integer field :temp_hi, :integer field :prcp, :float, default: 0.0 timestamps end end and then in the 'Query' part def sample_query do query = from w in Weather, where: w.prcp > 0.0 or is_nil(w.prcp),

What is the different between web/static and priv/static in phoenix?

北城余情 提交于 2020-01-13 11:29:13
问题 I am new to elixir and phoenix. Now I have trouble with the static assets in phoenix. I want to add a js file in my page, and I add the following code in my template: <script src="<%= static_path(@conn, "/js/test.js") %>"></script> and then create a js file at web/static/js/test.js . However, I got the error about test.js is not found in the browser's console. I notice there is a priv/static/js folder, and I try to create the js file at priv/static/js/test.js . This time, the error gone. I am

How to add a custom error message for a required field in Phoenix framework

家住魔仙堡 提交于 2020-01-13 10:12:49
问题 How can I change the error message for required fields? If I have something like that @required_fields ~w(name email) and I want to show "no way it's empty" instead of the default value of "can't be blank" ? 回答1: The "can't be blank" error message is hardcoded into Ecto at the moment. However, you can replace this error message by doing: def changeset(model, params \\ :empty) do model |> cast(params, @required_fields, @optional_fields) |> required_error_messages("no way it's empty") end def

How to add a custom error message for a required field in Phoenix framework

你说的曾经没有我的故事 提交于 2020-01-13 10:12:09
问题 How can I change the error message for required fields? If I have something like that @required_fields ~w(name email) and I want to show "no way it's empty" instead of the default value of "can't be blank" ? 回答1: The "can't be blank" error message is hardcoded into Ecto at the moment. However, you can replace this error message by doing: def changeset(model, params \\ :empty) do model |> cast(params, @required_fields, @optional_fields) |> required_error_messages("no way it's empty") end def

Generate signature in Elixir and PHP using hmac

只愿长相守 提交于 2020-01-13 09:55:14
问题 I try to generate a signature using Elixir, which has a same value as PHP does. For example the code in PHP is $signature = base64_encode(hash_hmac("sha256", "abc", "def")); and the output will be Mzk3ZjQ2NzM0MWU0ZDc4YzQ3NDg2N2VmMzI2MWNkYjQ2YzBlMTAzNTFlOWE5ODk5NjNlNmNiMmRjZTQwZWU1ZA== How should I generate the signature that has the same value in Elixir. I tried something like below iex(9)> :crypto.hmac(:sha256, "abc", "def") |> Base.encode64 │ "IOvA8JNERwE081BA9j6pix2OQUISlJ7lxQBCnRXqsIE="

Raw SQL with Ecto

安稳与你 提交于 2020-01-13 08:16:51
问题 I'm very new in the world of Elixir and Phoenix Framework. I'm trying to follow TheFireHoseProject tutorial, but having problems with querying raw SQL with Ecto. The tutorial says this should work: defmodule Queries do def random do query = Ecto.Adapters.Postgres.query( Repo, "SELECT id, saying, author from quotes ORDER BY RANDOM() LIMIT 1", []) %Postgrex.Result{rows: [row]} = query {id, saying, author} = row %Splurty.Quote{id: id, saying: saying, author: author} end end I'm getting a runtime

Raw SQL with Ecto

旧街凉风 提交于 2020-01-13 08:16:26
问题 I'm very new in the world of Elixir and Phoenix Framework. I'm trying to follow TheFireHoseProject tutorial, but having problems with querying raw SQL with Ecto. The tutorial says this should work: defmodule Queries do def random do query = Ecto.Adapters.Postgres.query( Repo, "SELECT id, saying, author from quotes ORDER BY RANDOM() LIMIT 1", []) %Postgrex.Result{rows: [row]} = query {id, saying, author} = row %Splurty.Quote{id: id, saying: saying, author: author} end end I'm getting a runtime