I am making my first Phoenix app and am trying to make a new / 2 controller. The code I wrote is
def new(conn, %{"fbid" => fbid, "latitude" => lat, "longitude" => lng, "content" => content}) do {fbid, _} = Integer.parse(fbid); {lat, _} = Float.parse(lat); {lng, _} = Float.parse(lng); chats = %Chat{:fbid => fbid, :latitude => lat, :longitude => lng, :content => content} |> Repo.insert |> List.wrap |> Poison.encode! render conn, chats: chats end
But it looks terribly redundant, and I cannot find a better way to do this. I read that there is no way to convert Map to Struct, and since the parameters are different in type, it still won't work.
So can someone show me some magical way to display it?
source share