Combinating Controller and Live View goes wrong /Phoenix/

Hi, I have created a phx.gen.html resource and want to use Live View only on show.html.leex page.

    resources "/websites", WebsiteController, except [:show]
    live "/websites/:id", WebsiteLive

where in Live

  def render(assigns) do
   render WebsiteView, "show.html", assigns
  end

Everything in websites’s show pages work perfectly, but as I cut out the :show option in resources "/websites" the compiler gives me an error that no action :show for AppWeb.Router.Helpers.website_path/3. So my question is how to define that the show option should be sought at the Live?

Best Regards

1 Like

Hi,

Maybe try with live "/websites/:id", WebsiteLive, :show ?

This path should be available at Router.Helpers.website_path(socket, :show, your_id)

2 Likes

Yeah, that is a solution, thanks :slight_smile:

Actually, I just tried to change my link to show template, from:

Routes.website_path(@conn, :show, website) %>

to

Routes.live_path(@conn, AppWeb.WebsiteLive, website)

and it worked,

Best Regards!

2 Likes

Cool!

You can also run mix phx.routes to get an overview of all routes available with the correct path syntax.

1 Like