Hi,
I’m getting stuck on how to pass in a value to live_redirect, I have a list of states and want to pass them through as a param on the URL. I’m trying to pass them as ‘item’ but no luck
<%= for item <- ['melbourne', 'sydney', 'brisbane', 'adelaide', 'perth', 'canberra', 'darwin', 'hobart'] do %>
<%= live_redirect String.capitalize("#{item}") , to: Routes.energy_raters_path(@socket, :index, item) %>
<% end %>```
Thanks for taking a look.
I gave that a try but I get the error:
Phoenix.Param not implemented for [state: 'melbourne'] of type List. This protocol is implemented for the following type(s): Any, Map, Integer, BitString, Atom
Thanks @kokolegorille yes charlist is not what I wanted, have updated to use double quotes.
I also needed to update my router path to not include /:city and can now see it passing through as ?city=melbourne. Is it possible to pass it as just /melbourne as it’s a nicer pattern?
# in the Router
live "/energy-rating-path", EnergyRatersLive, :index
live "/energy-rating-path/:city", EnergyRatersLive, :show
# You could call it like so now
<%= for city <- @cities do %>
<%= live_redirect String.capitalize("#{city}") , to: Routes.energy_raters_path(@socket, :show, city) %>
<% end %>
#In your LiveView
def mount(%{"city" => city}, _session, socket) do
...
end