user1354934
user1354934

Reputation: 8851

phoenix socket multiple assign

I want to add a few data into socket but wondering what the best way to do that would be.

Instead of doing a bunch of

socket = assign(socket, :channel_id, channel_id)

Upvotes: 2

Views: 1096

Answers (1)

Daniel
Daniel

Reputation: 2554

There is an alternative function assign/2 that allows assigning multiple values at once, by passing either map or keyword list:

assign(socket, name: "Elixir", logo: "💧")
assign(socket, %{name: "Elixir"})

Upvotes: 8

Related Questions