lc0815

lc0815

hello from a real frustrated newbe…

I’m reading this article Full-Stack React With Phoenix (Chapter 3 | Introduction to Phoenix) by michael mangialardi from the medium library. in it he’s adding a new Hello controller and I follow the to the letter on all fo the files he creates but I keep getting the error: Phoenix.Router.NoRouteError at GET /hello/phoenix

no route found for GET /hello/phoenix (HelloPhoenixWeb.Router)

and the only thing that is different is he is using version 1.3 of phoenix and I’m using the latest version.

for something this simple both version should work… but alas no matter what I try, it DOES NOT WORK FOR me…

Showing Posts 1 to 10

NobbZ

NobbZ

How does your routes.ex look like? What is the output of mix phx.routes?

lc0815

lc0815 OP

mix phx.routes output:
Returning_from_des>mix phx.routes
page_path GET / HelloPhoenixWeb.PageController :index
hello_path GET /hello:data HelloPhoenixWeb.HelloController :message
live_dashboard_path GET /dashboard Phoenix.LiveView.Plug :home
live_dashboard_path GET /dashboard/:page Phoenix.LiveView.Plug :page
live_dashboard_path GET /dashboard/:node/:page Phoenix.LiveView.Plug :page
websocket WS /live/websocket Phoenix.LiveView.Socket
longpoll GET /live/longpoll Phoenix.LiveView.Socket
longpoll POST /live/longpoll Phoenix.LiveView.Socket
websocket WS /socket/websocket HelloPhoenixWeb.UserSocket

thank you for your reply

lc0815

lc0815 OP

route.ex content:

defmodule HelloPhoenixWeb.Router do

use HelloPhoenixWeb, :router

pipeline :browser do

plug :accepts, ["html"]

plug :fetch_session

plug :fetch_flash

plug :protect_from_forgery

plug :put_secure_browser_headers

end

pipeline :api do

plug :accepts, ["json"]

end

scope “/”, HelloPhoenixWeb do

pipe_through :browser

get "/", PageController, :index

get "/hello:data", HelloController, :message

end

if Mix.env() in [:dev, :test] do

import Phoenix.LiveDashboard.Router

scope "/" do

  pipe_through :browser

  live_dashboard "/dashboard", metrics: HelloPhoenixWeb.Telemetry

end

end

end

kokolegorille

kokolegorille

Can You provide the lib/hello_phoenix_web/controllers/hello_controller.ex?

lc0815

lc0815 OP

here it is:

defmodule HelloPhoenixWeb.HelloController do
  use HelloPhoenixWeb, :controller

  def message(conn, %{"data" => data}) do
    render conn, "hello.html", :data
  end
end

t0t0

t0t0

I don’t know if it is some kind of typo but an important / is missing here between /hello and :data

lc0815

lc0815 OP

now I get this… after the / was included:

FunctionClauseError at GET /hello/phoenix

no function clause matching in Phoenix.Controller.render/3

t0t0

t0t0

Phoenix.Controller.render/3 expects a Keyword or a Map as assigns, not an atom.

So: render conn, "hello.html", data: data (Keyword), for example, like given in the tutorial you follow

kokolegorille

kokolegorille

As mentionned, You need to add the /

get "/hello/:data", HelloController, :message

It should be

render conn, "hello.html", data: data

The third argument should be a Keyword.

Well, @t0t0 get it right before koko :slight_smile:

lc0815

lc0815 OP

thank you, that did it…

I missed the / between the hello and the :data, so I started making changes to see what worked making things worse, now I can continue with my article. thanks again, great job… this really helps…
:slight_smile:

— All posts loaded —

Where Next? Top

Trending in Chat/Questions Top

krisleech
Hey folks, I’ve been using Elixir for over a couple of years (phx, ecto, broadway, oban). For this kind of work you do not tend, in my e...
New
mhindujadheerajsudan
Hi, I’m Dheeraj Sudan from the UK. I’m a software developer and also run a business with my wife Meenu Hinduja. I’m interested in getting...
New

Other Trending Topics Top

JesseHerrick
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews