Elixir "no match of right hand side value" in controller Phoenix

1.8k views Asked by At

I'm using the framework Phoenix with Ecto Mongo and I'm trying to get all Groups(My model) and loop this in view.

@groups = Group |> GlobalDocs.Repo.all

And I'm getting this message error:

no match of right hand side value: [%Group{__meta__: #Ecto.Schema.Metadata<:loaded>, avatar_url: nil, description: "", group_id: 123, id: "585ea2ce6e8dee0a6c04ecf6", name: "TryGroup", slug: "try_group"}]

Why this? If I run this in IEx, this code works.

Thanks for this.

1

There are 1 answers

0
Justin Wood On

Elixir and Phoenix do not work the same way as Ruby and Rails does.

When you use an @ variable. They are called module attributes. In Phoenix, you do not use module attributes in order to have a variable accessible in a view like you would with rails.

In Phoenix, you would use something like the following.

groups = GlobalDocs.Repo.all(Group)

render conn, "index.html", groups: groups

Now, in your view, you will have access to a @groups variable.