elixir - How to handle success/error flash messages from Rethinkdb in Phoenix -


i'm trying success or insuccess of query rethinkdb in phoenix framework through flash message. don't know correct signature retrieve result message rethinkdb in code block.

def index(conn, _params)    #query creates table in database     table_create("contenttext")     |> basedados.database.run       # list elements of table database     q = table("contenttext")       |> basedados.database.run #run query through database       |> io.inspect     conn     |> put_flash(:error, "some message")     |> put_flash(:info, "another message")     |> render "index.html", contenttext: q #render users searched on users template   end 

edit: okay found out there supposed errors field along lines of:

%rethinkdb.record{data: %{"deleted" => 0, "errors" => 0, "generated_keys" => ["15cc4e19-fc72-4c19-b3a5-47141b6a63e0"], "inserted" => 1, "replaced" => 0, "skipped" => 0, "unchanged" => 0}} 

however don't seem have (i tried q.errors , q.data.errors) , error every time. error i'm testing if database table not exist (i change contenttext else entirely).

i'm able error checking data:

q = table("contenttext")   |> basedados.database.run #run query through database  if is_nil(q.data)   conn   |> put_flash(:error, "error")   |> render "index.html", contenttext: "failed" #render users searched on users template else   conn   |> put_flash(:info, "sucess")   |> render "index.html", contenttext: q #render users searched on users template end 

however seems limited solution detects if there data in message. error can else entirely. , since field seems count them value , use in condition instead (if errors > 0). need field?

use q.data["errors"]) instead of q.data.errors.

according issue hamiltop/rethinkdb-elixir#59, can use q.data["r"] on failure.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -