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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -