aligredo
Hello there,
I have a simple :create action in my controller and everytime I try submitting the form with invalid data it redirects to the :index route without showing any error_tag
here is my code:
controller
def new(conn, _params) do
changeset = Accounts.change_student(%Student{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"student" => student_params}) do
case Accounts.create_student(student_params) do
{:ok, student} ->
conn
|> put_flash(:info, "Welcome aboard, You Should Recieve A Confirmation Mail Soon!")
|> redirect(to: Routes.student_path(conn, :show, student))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
Changeset:
def changeset(student, attrs) do
student
|> cast(attrs, [:username, :password, :firstName, :lastName, :birthdate, :gender, :email, :uniID])
|> validate_required([:username, :password, :firstName, :lastName, :birthdate, :gender, :email, :uniID])
|> unique_constraint(:username)
|> unique_constraint(:email)
end
Form Templae:
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<%= label f, :username %>
<%= text_input f, :username %>
<%= error_tag f, :username %>
<%= label f, :password %>
<%= password_input f, :password %>
<%= error_tag f, :password %>
<%= label f, :firstName %>
<%= text_input f, :firstName %>
<%= error_tag f, :firstName %>
<%= label f, :lastName %>
<%= text_input f, :lastName %>
<%= error_tag f, :lastName %>
<%= label f, :birthdate %>
<%= date_select f, :birthdate %>
<%= error_tag f, :birthdate %>
<%= label f, :gender %>
<%= select f, :gender, ["Male", "Female", "Other", "Rather Not Specify"] %>
<%= error_tag f, :gender %>
<%= label f, :email %>
<%= text_input f, :email %>
<%= error_tag f, :email %>
<%= label f, :uniID %>
<%= text_input f, :uniID %>
<%= error_tag f, :uniID %>
<div>
<%= submit "Submit" %>
</div>
<% end %>
UPDATE: I noticed that it also does not insert when the data is valid so it a problem with the DB I think, can you help me with that?
Thanks in advance!
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Latest Phoenix Threads
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
al2o3cr
Your original issue sounds like the changeset isn’t getting an
actionset on it; can you post yourAccounts.create_studentfunction?aligredo
yes, sure. Here you go
stefanchrobot
Can you show us the schema and DB migration as well? One thing that caught my eye was the unusual naming:
firstName. Is this aligned with the DB definition?Can you try creating the student from IEx session?
aligredo
yes sure,
Schema:
Migration:
iex session output:
stefanchrobot
I’m no expert in Phoenix, but shouldn’t this point to a correct route instead of
@action? What’s the value of the@actionassign?LostKobrakai
The phoenix generators create
new.html.eexandedit.html.eex, which both renderform.html.eexsetting@actionto an appropriate value.aligredo
exactly, here is it
stefanchrobot
Makes sense, but I’m out of ideas then. I’m not sure you’re posting the complete code, since there seems to be some missing parts (like password hashing). Do you happen to have any plugs (auth?) that would redirect the user?
aligredo
Not yet I’m just setting up the accounts context, I think the problem is with my
router.exnot with validationscheck this New Topic I added my router code there.
Thank you so much!