shirawebill
Error: no function clause matching in .AddSiteLive.handle_params/3
Hi, I am using push_patch with handle_params but I am hitting this error:
def handle_params(%{“page” => page}, _, socket) do
Logger.info(“handle params”)
case page do
1 ->
socket = assign(socket, page: 1)
{:noreply, push_patch(socket, to: "/portfolio/add-site")}
2 ->
socket = assign(socket, page: 2)
{:noreply, push_patch(socket, to: "/portfolio/add-site")}
end
end
This is what my html page looks like:
<%= if (@page == 2) do %>
<.live_component module={Web.SiteTypeComponent} id=“1” params={@params} changeset={@changeset} page={@page} type={@type} location={@location_input} coords={@coords}/>
<%= else %>
…
<%= live_patch “Continue”, to: Routes.live_path(@socket, Web.AddSiteLive, page: 2), class: “btn-primary-medium” %>
I’m not sure what a I am doing wrong - I want the continue button to load the component for page 2
Thanks! ![]()
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Hello !
We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security











First 6 of 6 Posts!
soup
Please post the actual error message and your
router.ex(just the part that includes the route you want to link to).shirawebill
Hi,
Thank you.
I refactored my page a bit and I am no longer getting the error message.
I needed to have 2 handle_params defined, and both are running every time I click “continue”
The issue now is that my page “1” is not being rendered correctly from page “2” - I am missing parts, it’s not loading correctly.
def handle_params(%{“page” => page}, _, socket) do
Logger.info(“handle params 1”)
end
def handle_params(params, _, socket) do
Logger.info(“handle params 2”)
Logger.info(params)
{:noreply, socket}
end
HTML:
<%= if (@page == 2) do %>
<.live_component module={WB.PortfolioWeb.SiteTypeComponent} id=“1” params={@params} changeset={@changeset} page={@page} type={@type} location={@location_input} coords={@coords}/>
<%= else %>
…
<%= live_patch “Continue”, to: Routes.live_path(@socket, WB.PortfolioWeb.AddSiteLive, page: 2), class: “btn-primary-medium” %>
<% end %>
In the component:
<%= live_patch “Site Type & Location”, to: Routes.live_path(@socket, Web.AddSiteLive, page: 1), class: “” %>
Router.ex:
live(“/portfolio/add-site”, AddSiteLive)
soup
The reason you were getting a no match the first time is that you were only matching when
paramsexplicitly has the form%{"page" => page}. When you first hit the page, you wont have any query params set, soparamswill look like this:%{}and Elixir cant find any function that accepts those arguments.The error message will say something like
Which is cluing you into what params were given (the
%{}) and what the error is.and you’ll see this rendered:
Now your second
handle_paramswill always match as a last resort since it effectively has no pattern constraint.I doubt you want the
push_patch, just update thepageinassignsand return the updated socket, LiveView will do the rest. This is probably why you’re seeing something run twice.You might want to re-read the LiveView life cycle stuff in the docs. You may want to refresh yourself on pattern matching, and please post the actual error log next time. Also please try to post with formatting, otherwise it’s hard to follow.
shirawebill
Thank you for your help.
I specifically want to use the push patch because I want the input on page 1 to still be there when I go back from the component to page 1, if you understand what I’m saying?
Can you help with that?
benwilson512
What should happen if someone removes
pagefrom the URL params? It is not possible to guarantee that it is there, users can always remove it. You need to handle a case where it is not present, and set a default if it is not there.shirawebill
That is a good point.
Thank you for your help.