elixir

When accessing front-end SPA-links from browser, back-end fires finding no route

∥☆過路亽.° 提交于 2020-02-05 07:40:12
问题 I have a working front-end single-page-application written in JS (ReactJS), and a working back-end in Phoenix (Elixir). Everything works out fine as long as navigation happens within the application. However, when I try to access a page in the SPA from the browser, I get a route error fired from Phoenix. For example: no route found for GET /search (PhoenixApp.Router) is what I get when I access http://localhost:4000/search from the browser. When I access http://localhost:4000/search from the

Elixir assert_raise doesn't catch exceptions

只谈情不闲聊 提交于 2020-02-03 03:56:45
问题 I wrote this test case: assert_raise ArgumentError, myFn(a,b) but it does not evaluate in the way I'd expect. myFn raises an ArgumentError ( do: raise ArgumentError ), but it is not caught by assert_raise . The example in the docs works just fine: assert_raise ArithmeticError, fn -> 1 + "test" end From the documentation: assert_raise(exception, function) Asserts the exception is raised during function execution. Returns the rescued exception, fails otherwise I'm guessing that in my test case,

Why I got #Ecto.Association.NotLoaded?

假如想象 提交于 2020-01-31 07:12:22
问题 I have teams and each team has users, so there is a join table to link users to teams as its a many to many relation, here is my models: defmodule App.Team do use App.Web, :model schema "teams" do field :owner_id, :integer has_many :team_users, {"team_user", App.TeamUser} end end defmodule App.User do use App.Web, :model schema "users" do # field :email, :string has_many :team_user, App.TeamUser end end And here is the join model: defmodule App.TeamUser do use App.Web, :model @primary_key

after_validation equivalent to create ancestors

[亡魂溺海] 提交于 2020-01-25 10:14:14
问题 The application stores locations which can belong_to one parent can have multiple ancestors During the create_location I want to add just the parent_id . The ancestors should be created automatically (including a position field to store the hierarchy level). The tree is not endless. We are talking about 4 levels. Example: USA <- California <- San Francisco <- Mission St Setup mix phx.new example cd example mix ecto.create mix phx.gen.html Maps Location locations name parent_id:references

after_validation equivalent to create ancestors

六月ゝ 毕业季﹏ 提交于 2020-01-25 10:14:13
问题 The application stores locations which can belong_to one parent can have multiple ancestors During the create_location I want to add just the parent_id . The ancestors should be created automatically (including a position field to store the hierarchy level). The tree is not endless. We are talking about 4 levels. Example: USA <- California <- San Francisco <- Mission St Setup mix phx.new example cd example mix ecto.create mix phx.gen.html Maps Location locations name parent_id:references

How to raise custom Postgresql error and handle it in Ecto

耗尽温柔 提交于 2020-01-24 22:52:27
问题 I created a custom function in Postgresql that checks data before insert or update and raises error if something goes wrong. CREATE FUNCTION custom_check() RETURNS TRIGGER AS $$ BEGIN IF <SOME CONDITION> THEN RAISE EXCEPTION 'CUSTOM ERROR'; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql """) When I'm using constraints in Postgresql, I can handle errors raised with Ecto.Changeset.check_constraint . But I didn't find a way to handle this error I'm raising, to reflect it in changeset instead of

How to selectively disable CSRF check in Phoenix framework

我的梦境 提交于 2020-01-22 13:19:30
问题 I'm trying to create a Facebook Page Tab which points to my website. Facebook sends a HTTP POST request to the url of my website. The problem here is that the server has a built-in CSRF check, and it returns the following error: (Plug.CSRFProtection.InvalidCSRFTokenError) invalid CSRF (Cross Site Forgery Protection) token, make sure all requests include a '_csrf_token' param or an 'x-csrf-token' header` The server expects a CSRF token that Facebook can't have. So, I want to selectively

What could cause the `net_adm` kernel Erlang module to be unavailable?

百般思念 提交于 2020-01-21 19:18:30
问题 Installed Erlang (releases from 19 to 22) using the Nix package manager apt and compiling from source on Ubuntu 18.04 with Xmonad and Debian 9 running in the cloud , but every time, net_adm is not available through the Erlang shell event though other kernel modules are. I assume that this is caused by an external system configuration because couldn't find anything about this online, so people are not complaining about it. (Only found one person so far.) 回答1: Kind of ashamed to admit that I am

How to run updating in migration for Ecto?

落爺英雄遲暮 提交于 2020-01-21 03:11:06
问题 I use Phoenix and Ecto in one of my project. I want to add a column to one table, and I expect it to be a NOT NULL column. But I already have some existed data, so I decide to add the column, update all rows to some value and modify the column to NOT NULL . I tried these two code: # solution 1 def up do alter table(:channels) do add :type, :integer Exchat.Repo.update_all("channels", set: [type: 1]) modify :type, :integer, null: false end end # solution 2 def up do alter table(:channels) do

Elixir/Phoenix binary_to_atom

白昼怎懂夜的黑 提交于 2020-01-20 08:55:26
问题 I have a form <%= select f, :user_id, ["刺繡等等我": "2", "wow": "3"] %> If I use only english language, it works perfectly. But chinese, or any other returns error ** (ArgumentError) argument error :erlang.binary_to_atom("刺繡等等我", :utf8) (elixir) src/elixir_parser.yrl:512: :elixir_parser.yeccpars2_93/7 I believe it has do to with the encoding. How can I convert the string to the acceptable format? Thanks in advance! 回答1: Atoms cannot contain codepoints above 255 as of the current version of Erlang