joseratts
have been 5 years since my last elixir/phoenix development, since then have been a lot of changes specially the change added in the v1.7
So I’m refreshing my knowledge doing again the exercises of the book programming phoenix 1.4 but I’m stuck in the chapter 3 Controllers figuring out how and where implement the function first_name than back in version v1.4 was like follow
defmodule RumblWeb.UserView do
use RumblWeb, :view
alias Rumbl.Accounts
def first_name(%Accounts.User{name: name}) do
name
|> String.split(" ")
|> Enum.at(0)
end
end
and then used by the template index.html.eex
Listing Users
<table>
<%= for user <- @users do %>
<tr>
<td><b><%= **first_name**(user) %></b> (<%= user.id %>)</td>
<td><%= link "View", to: Routes.user_path(@conn, :show, user.id) %></td>
</tr>
<% end %>
</table>
So, Any of you have a tutorial about how to apply this kind of logic in the new phoenix 1.7 I just have found this thread Programming Phoenix 1.4 book examples updated to 1.7 but I’m not pretty sure this is the only or the best way to do it
Thanks in advance
Trending in Questions
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #performance










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
joseratts
I have found a way to solved it using de GitHub repo published in Programming Phoenix 1.4 book examples updated to 1.7 thread. Even so I would like to know your feedback mainly to find the best way to do it
the user_html.ex file
controllers/user_html/index.html.heex
controllers/user_html/show.html.heex
The only thing make me feel I little bit uncomfortable with this approach is I haven´t found yet the way to reuse templates just like appears in the book where the template that shows user info is reused in the view that shows the list of users
sodapopcan
Views have essentially been swapped for components which you can define in a controller’s associated HTML module. It’s all detailed here.
In terms of your example, I tend to use components for everything, even these “helper” type functions. Some may find this gratuitous, and in this specific example it probably is, though of course splitting a string to get a first name is not a super realistic one (or at least not a good idea, lol):
Then you can use it like so:
This can just be a private component within your HTML module or put it somewhere else so you can import it anywhere.
joseratts
Thanks for answering @sodapopcan Following your approach I could do it in the following
way
user_html.ex
index.html.heex
I’m still getting used to the new way to do the things, but I think I can get it, So the idea is to define global or local componentes (that can take advantage of tailwind to have an style) and this components be reused even as nested componentes in other hex templates acting just like HTML tags with attributes and so on. If I’m wrong please do not hesitate in correct me in order to be able understand it.