Creating Some Users

Rather than bog down in a digression on databases, data libraries, and related concerns, let’s agree to keep things simple in the beginning. We’ll start with a few hard-coded users. This strategy will help us in the long run too, because it’ll allow us to test our actions, views, and templates quickly, without needing to create a full database underneath.

Let’s define a Rumbl.User module with the fields id, name, username, and password:

 defmodule​ Rumbl.User ​do
  defstruct [​:id​, ​:name​, ​:username​, ​:password​]

The User module defines an Elixir struct, which is Elixir’s main abstraction for working with structured data.

Elixir Structs

Elixir structs ...

Get Programming Phoenix now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.