elixir

Code.ensure_loaded? in .iex.exs

醉酒当歌 提交于 2019-12-11 05:53:08
问题 I have an elixir console configuration stored in .iex.exs : if Code.ensure_loaded?(MyApp.Repo) do alias MyApp.Repo end I want to have an ability to run both iex and iex -S mix . I'll have exception if I remove condition on iex . But this conditions doesn't work well! Even on iex -S mix I have (module Repo is not available) error if I'm trying to invoke Repo.get(...) . So, my questions are: Why Code.ensure_loaded? doesn't work here? How can I fix that? 回答1: This is a matter of scoping. Inside

Phoenix file copying on Heroku

≡放荡痞女 提交于 2019-12-11 05:40:31
问题 I'm trying to upload images to my Phoenix app on Heroku. I have a simple app that follows the instructions for file uploading from Phoenix's docs. I have a simple form and the controller uses File.cp_r() to copy the file from the temp directory. def create(conn, %{"user" => user_params}) do if upload = user_params["photo"] do File.cp_r(upload.path, "priv/static/images/foo.jpg") #non-dynamic name, doens't matter end ... end Works just file on my local. However when I upload this to Heroku,

“Dialyzer is usually never wrong”, but I can't figure out how my @spec is incorrect

…衆ロ難τιáo~ 提交于 2019-12-11 05:34:45
问题 I have some code that is failing dialyzer and I cannot understand why. No matter what I put into the @spec at the top of the function, calls to that function return a puzzling dialyzer error. Here is a simplification of the function. As far as I can tell, I have spec'd the function correctly. @spec balances(uuid :: String.t(), retries :: non_neg_integer) :: {:ok, list()} | {:internal_server_error, String.t(), String.t()} | {:internal_server_error, map | list, String.t()} def balances(uuid,

Elixir io_lib call to erlang

拥有回忆 提交于 2019-12-11 05:05:15
问题 io_lib:fread("~d/~d/~d", "2013/03/03"). Above code works in erlang so ideally in elixir below code should work :io_lib.fread("~d/~d/~d", "2013/03/03") but it generates error " no function clause matching " After inspecting found that elixir makes call to module like :io_lib_fread.fread("~d/~d/~d", "2013/03/03", 0, []) 回答1: A double quote in erlang "char list" translates to single quotes in Elixir 'char list' . 来源: https://stackoverflow.com/questions/18756293/elixir-io-lib-call-to-erlang

Edeliver - Impossible to access on port 4000 after successful deploy

大城市里の小女人 提交于 2019-12-11 04:58:50
问题 I'm trying to deploy a simple phoenix app with edeliver . Yesterday after many struggle it worked. Anyway, today I worked on it a bit and tried to release a new version: mix edeliver build release --branch=production # looks fine mix edeliver deploy release to production # looks fine mix edeliver restart production # looks fine If I run ps aux on my server I can see: root 29773 0.0 0.0 7620 292 ? S 08:58 0:00 /var/www/elixirhunt.prod/elixirhunt/erts-8.0/bin/epmd -daemon root 3179 0.0 0.0 4328

How to publish a package to hex with a dependency from github?

懵懂的女人 提交于 2019-12-11 04:27:32
问题 How do I publish a package to hex correctly that has a dependency from github and is required for the package to run? 回答1: You cannot. Only Hex packages will be included as dependencies of the package, for example Git dependencies will not be included. Source This is by design to make sure every package published on hex.pm can be built in the future. Github repositories can be deleted by the creator at any time but packages published on hex.pm cannot be unpublished after 1 hour of it being

Create a Map with an Integer Key

烈酒焚心 提交于 2019-12-11 04:06:03
问题 I want to create a map with a key of type integer, but this doesn't work: iex(1)> a = %{3: "fdsfd"} ** (SyntaxError) iex:1: unexpected token: ":" (column 8, codepoint U+003A) iex(1)> a = %{:3 => "fdsfd"} ** (SyntaxError) iex:1: unexpected token: ":" (column 7, codepoint U+003A) 回答1: To use an Integer as a key, simply use it like this: map = %{ 3 => "value" } :3 is an invalid value in Elixir; atoms are neither Strings or Integers in Elixir, they are constants where their name is their value.

Can't start a Elixir Phoenix as a mix release

烈酒焚心 提交于 2019-12-11 02:45:10
问题 I'm not able to start my project from a mix release . But it works fine if I run mix phx.server I'm able to recreate this problem from an empty project by doing: mix phx.new asdf --umbrella --no-ecto --no-html --no-webpack then edit mix.exs and add a release section: def project do [ apps_path: "apps", start_permanent: Mix.env() == :prod, deps: deps(), version: "0.1.0", releases: [ mega_umbrella: [ applications: [ mega: :permanent, mega_web: :permanent ] ] ] ] end then remove the last line

Pattern matching on a map with variable as key

非 Y 不嫁゛ 提交于 2019-12-11 02:27:24
问题 How can I do pattern matching on a map which has a string key? iex(1)> my_map = %{"key1" => "var1"} %{"key1" => "var1"} iex(2)> %{aa => bb} = my_map ** (CompileError) iex:2: illegal use of variable aa inside map key match, maps can only match on existing variable by using ^aa (stdlib) lists.erl:1354: :lists.mapfoldl/3 iex(2)> %{"aa" => bb} = my_map ** (MatchError) no match of right hand side value: %{"key1" => "var1"} 回答1: If the Map is guaranteed to have only 1 entry (like you clarified in

Elixir interpreter error

☆樱花仙子☆ 提交于 2019-12-11 02:24:22
问题 I was following elixir getting started where it says run: iex> i 'hello' so I ran: iex(1)> i 'hello' and got: ** (CompileError) iex:2: undefined function i/1 elixir version: Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false] Interactive Elixir (1.1.0-dev) 回答1: The function IEx.Helpers.i/1 , which the guide you linked to uses, was added in Elixir 1.2.0. You need to install Elixir 1.2.0 or later version to use it. see http://elixir-lang.org/install.html