phoenix-framework

Postgrex - No pg_hba.conf entry for host “xxx.xxx.xxx.xxx”

╄→гoц情女王★ 提交于 2019-12-23 12:27:24
问题 I have a Postgres Database hosted separately which I'm trying to use with my Phoenix Application. My prod config is: config :my_app, MyApp.Repo, adapter: Ecto.Adapters.Postgres, url: "postgres://username:password@myhost:5432/my_database", size: 20 This worked fine while my application was hosted on Heroku, but since I've moved it to a VPS, I keep getting this error: 17:07:13.665 [info] GET /subjects 17:07:13.707 [info] Processing by MyApp.SubjectController.index/2 Parameters: %{"format" =>

How to debug eex template and @ variables?

故事扮演 提交于 2019-12-23 10:06:59
问题 I have this template <%= form_for @changeset, bid_path(@conn, :update, 1), [method: :put], fn f -> %> <% require IEx IEx.pry %> <%= if @changeset.action do %> <div class="alert alert-danger"> <p>Oops, something went wrong! Please check the errors below.</p> </div> <% end %> How can I display @changeset in IEx console? When I'm trying to do this is blows an error: pry(5)> @changeset ** (ArgumentError) cannot invoke @/1 outside module (elixir) lib/kernel.ex:3960: Kernel.assert_module_scope/3

How to implement user authentication in phoenix

不打扰是莪最后的温柔 提交于 2019-12-23 09:25:55
问题 I was creating a webapp in phoenix, I was wondering what could be a better way to implement user registration/authentication and session management in it. On googling I found these two libraries: addict and passport But I am not sure how much stable are these and are they being used in production somewhere. Please let me know if there are some libraries safe to use in production and if there are some example implementation of those. 回答1: Addict seems to be the more mature project and appears

How to test that a Phoenix socket is terminated?

强颜欢笑 提交于 2019-12-22 18:11:51
问题 I'm looking for a way to test that a socket gets terminated. The code under test does this: def handle_in("logout", _payload, socket) do {:stop, :logout, socket |> assign(:user, nil)} end And my test code (adapted from http://elixir-lang.org/getting-started/try-catch-and-rescue.html#exits) does this: test "logout terminates the socket", %{socket: socket} do try do push socket, "logout" catch huh -> IO.puts("Caught something #{IO.inspect huh}") :exit, what -> IO.puts("Caught :exit #{IO.inspect

Generating initials avatar with Elixir [closed]

拥有回忆 提交于 2019-12-22 09:59:51
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I am working on Elixir and looking to make an avatar service. If the user doesn't have an avatar, want to make one with their initials on it, like so: I really haven't the slightest idea where to start or how to do this. 回答1: You can use ImageMagick to do this. Simply call the

Upgrading React-Router and replacing hashHistory with browserHistory

僤鯓⒐⒋嵵緔 提交于 2019-12-22 08:29:56
问题 I have a bootstrap+react theme that was using react-router 1.x and hashHistory and I wanted to remove the hash so followed this advice. Initially I tried to do this while having the 1.x version and I was unable to do it so I've decided to upgrade react-router to 2.x. After installing react-router 2.x the app worked because it was still using hashHistory but when I replaced it with browserHistory: it showed a grey screen the HTML of the app had only the <noscript data-reactid=".0"></noscript>

Socket won't connect to Endpoint

故事扮演 提交于 2019-12-22 06:56:19
问题 var socket = new Socket("localhost:4000") socket.connect() Returns WebSocket connection to 'ws://localhost:4000/ws' failed: Error during WebSocket handshake: Unexpected response code: 404 But I do have the socket on the /ws endpoint, right? defmodule Sapphire.Endpoint do use Phoenix.Endpoint, otp_app: :sapphire socket "/ws", Sapphire.MomentSocket plug Plug.Static, at: "/", from: :sapphire, gzip: false, only: ~w(css fonts images js favicon.ico robots.txt) if code_reloading? do socket "/phoenix

Phoenix channels: send push to a particular client

点点圈 提交于 2019-12-22 06:48:10
问题 Hi I am trying to reimplement whatsapp functionality using elixir phoenix. I am having a problem figuring out the following: if all people in the chat room has received the message, I want to send the owner of the message status "received" so that he can show double tick sign. However how do you broadcast to one particular client? 回答1: You can solve this via topic per user, this can be easily implemented by pattern matching, notice the security validation also: def join("users:" <> user_id,

How to use Geo library to create valid Ecto Model changeset?

烈酒焚心 提交于 2019-12-22 04:39:20
问题 I'm trying to use Geo library to store Geo.Point via Phoenix model changeset. My params are: {coordinates: [49.44, 17.87]} or more prefer would be {coordinates: {latitude: 49.44, longitude: 17.87}} In iex console I tried: iex(5)> changeset = Place.changeset(%Place{}, %{coordinates: [49.44, 17.87]}) %Ecto.Changeset{action: nil, changes: %{}, constraints: [], errors: [coordinates: "is invalid"], filters: %{} model: %Myapp.Place{__meta__: #Ecto.Schema.Metadata<:built>, coordinates: nil, id: nil,

How to get a variable value from Environment files in Phoenix?

时光总嘲笑我的痴心妄想 提交于 2019-12-22 02:21:11
问题 I'm deploying my first Phoenix Application, and I've specified the values of a variable in my Environment Files ( dev.exs and prod.exs ). Now I'm trying to figure out how to access them in my Controllers. # config/dev.exs config :my_app, MyApp.Endpoint, http: [port: 4000], debug_errors: true, cache_static_lookup: false, my_var: "DEVELOPMENT VALUE" # config/prod.exs config :my_app, MyApp.Endpoint, http: [port: {:system, "PORT"}], url: [host: "example.com"], my_var: "PRODUCTION VALUE" 回答1: Okay