Error in creating registration form using form_for html helper.

I am encountering an error while designing a registration page using form_for html helper. The code is-

<h1>Register account</h1>

<%= form_for @changeset, registration_path(@conn, :create), [as:
:registration, id: "registration-form"], fn f -> %>

<div class="form-group">

<%= label f, :name, class: "control-label" %>

<%= text_input f, :name, class: "form-control" %>

<%= error_tag f, :name %>


<%= submit "Register", class: "btn btn-primary" %>

<% end %>

And the error is-

Compilation error in file lib/manage_contracts_web_web/views/registration_view.ex ==
** (CompileError) lib/manage_contracts_web_web/views/registration_view.ex:2: undefined function registration_path/2

Please help me resolve this error.

Hi, you missed the alias Routes, should be fixed by using Routes.registration_path.

To elaborate a bit more. In previous versions of phoenix the route helpers were imported into view modules. To improve on issues with increasing compile times this has been changed to only an alias, which is why the Routes. code prefix is now required.

1 Like