The pipe chain must start with a raw value
My Phoenix App Controller has the following action:
def index(conn, params) do
studios =
if params["search"] do
Studio.search(Studio, params["search"])
else
Studio
end
|> Repo.all
|> Repo.preload(:address)
render conn, studios: studios
end
When my startup mix credo
returns the following warning:
┃ [F] → Pipe chain should start with a raw value.
┃ lib/tattoo_backend/web/controllers/api/v1/studio_controller.ex:21 #(TattooBackend.Web.API.V1.StudioController.index)
I tried to refactor this, but I haven't found a solution that makes the creed happy. Any ideas how to solve this?
+3
source to share
3 answers
if foo do
bar
else
baz
end
is equivalent if(foo, do: bar, else: baz)
. Once you know this, you can understand what the error message means: params["search"]
should be passed to if
. This should fix the warning:
def index(conn, params) do
studios =
params["search"]
|> if do
Studio.search(Studio, params["search"])
else
Studio
end
|> Repo.all
|> Repo.preload(:address)
render conn, studios: studios
end
+1
source to share