elixir - Partial updates in Phoenix and function signature -
i want create partial update method via ajax/json. how should "update" function like?
def update(conn, %{"a" => a, "b" => b, "c" => c} = params) # .... end
namely, 1 of these parameters required at time. how can specify that? or should instead this:
def update(conn, params) # .... end
check if params contains a
, b
or c
?
you can use pattern matching define possibilities:
def update(conn, %{"a" => a} = params) # when have "a" end def update(conn, %{"b" => b} = params) # when have "b" end def update(conn, %{"c" => c} = params) # when have "c" end def update(conn, params) # handle else end
Comments
Post a Comment