Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 14, 2023 01:54 am GMT

Using Live Suffix in LiveView

When using LiveView and you don't include Live inside your module name an error like this can appear:

Example: defmodule RankmodeWeb.Profiles.Index do, will throw Live Suffix Error.

Live Suffix Error

For example in my Rankmode Live Profiles module

If we change the module to RankmodeWeb.ProfilesLive.Index it will run. But there is a secret option that will be valid too RankmodeWeb.Live.Profiles.Index

By using Live as a Phoenix Context we can improve our code organization and avoid having to type Live at the end of the module name.

We can see how the router.ex is improved.

scope "/", RankmodeWeb do    pipe_through [:browser, :require_authenticated_user]    live "/profiles", Live.Profiles.Index, :index    live "/profiles/new", Live.Profiles.New, :new    live "/profiles/edit/:profile", Live.Profiles.Edit, :edit    live "/profiles/:profile/gameplays", Live.Gameplays.Index, :index    live "/profiles/:profile/gameplays/new", Live.Gameplays.New, :new    live "/profiles/:profile/gameplays/edit/:gameplay", Live.Gameplays.Edit, :editend

And our files structure can be improved as well.

file organization


Original Link: https://dev.to/clsource/using-live-suffix-in-liveview-2m07

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To