Error in phx.gen.live generated leex files

Hello there,

After phx.gen.live in this particular file “show.html.leex” it says “undefined function live_modal/3”. In the index.html.leex it does not show that error.

Compilation error in file lib/real_estate_web/live/property_live/show.ex ==
(CompileError) lib/real_estate_web/live/property_live/show.html.leex:4: undefined function live_modal/3

Thanks

It’s because You did not create the project with the --live parameter, just create a dummy with --live, and check in the live directory for the modal file.

I created the project with the --live parameter. Only in one particular generated .leex file this error pops up. In the .leex files the “live_modal/3” function does not show any error

ok, my bad… but You would have better answer if You show the code leading to this error.

Thanks for your support.

After generating phx.gen.live files while doing ecto.migrate i receive a compile error showing “live_modal/3” undefined in the .leex template files. Below is the entire code from the terminal starting from generating phx.gen.live

anil@admin:~/projects/elixirapps/real_estate$ mix phx.gen.live Properties Property properties user_id:references:users name:string price:decimal description:text
The following files conflict with new files to be generated:

  • test/real_estate_web/live/property_live_test.exs

See the --web option to namespace similarly named resources

Proceed with interactive overwrite? [Yn] y

  • creating lib/real_estate_web/live/property_live/show.ex
  • creating lib/real_estate_web/live/property_live/index.ex
  • creating lib/real_estate_web/live/property_live/form_component.ex
  • creating lib/real_estate_web/live/property_live/form_component.html.leex
  • creating lib/real_estate_web/live/property_live/index.html.leex
  • creating lib/real_estate_web/live/property_live/show.html.leex
  • creating test/real_estate_web/live/property_live_test.exs
  • creating lib/real_estate_web/live/modal_component.ex
  • creating lib/real_estate/properties/property.ex
  • creating priv/repo/migrations/20210112030745_create_properties.exs
  • creating lib/real_estate/properties.ex
  • injecting lib/real_estate/properties.ex
  • creating test/real_estate/properties_test.exs
  • injecting test/real_estate/properties_test.exs

Add the live routes to your browser scope in lib/real_estate_web/router.ex:

live "/properties", PropertyLive.Index, :index
live "/properties/new", PropertyLive.Index, :new
live "/properties/:id/edit", PropertyLive.Index, :edit

live "/properties/:id", PropertyLive.Show, :show
live "/properties/:id/show/edit", PropertyLive.Show, :edit

Remember to update your repository by running migrations:

$ mix ecto.migrate

anil@admin:~/projects/elixirapps/real_estate$ mix ecto.migrate
Compiling 10 files (.ex)

== Compilation error in file lib/real_estate_web/live/property_live/show.ex ==
**** (CompileError) lib/real_estate_web/live/property_live/show.html.leex:4: undefined function live_modal/3**
** (elixir 1.10.4) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3**
** (stdlib 3.13.2) erl_eval.erl:680: :erl_eval.do_apply/6**
** (elixir 1.10.4) lib/kernel/parallel_compiler.ex:304: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7**

Phoenix should have generated a LiveHelpers file for you which should be included in the def live do section of your lib/real_estate_web/web.ex like this:

import RealEestateWeb.LiveHelpers

That’s the file that defines live_modal. Something has gone wrong or missing somewhere for this entry to be missing.

1 Like

There seems to be some missing somewhere. Restarting the project might work. Thanks for the support Jose.