An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
January 14, 2023 01:54 am GMT
Original Link: https://dev.to/clsource/using-live-suffix-in-liveview-2m07
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.
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.
Original Link: https://dev.to/clsource/using-live-suffix-in-liveview-2m07
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To