remmy

remmy

Programming Phoenix 1.4: Chapter 7: Doesn't mention how to actually get the form validation error for category select (page 140)

Hello,

At the end of page 140 the book implies that assoc_constraint means that you should get a descriptive form validation error when submitting the video new/edit form with a category ID that doesn’t exist:

As with unique_constraint, when we set up assoc_constraint, we no longer get Ecto.ConstraintError. Instead, they’re converted into changeset error messages.

You can try to reproduce this constraint error via our web application in a couple of ways. For example, you could load the page, then remove the category from the database and submit the form after choosing the removed category. If you feel a bit more sneaky, you can fiddle the select options in the browser console, changing their value and then submitting the form.

However, the book never tells you to add an error_tag to the category select field, nor is it included in the source code that comes with the book, so there is in fact no way to just reproduce the error in the web application as per the book.

Intuitively I would also have expected to be able to use <%= error_tag f, :category_id %>, since the actual select field is named like that:

<%= select f, :category_id, category_select_options(@categories), prompt: "Choose a category" %>

But since it’s an assoc_constraint on :category the actual error is on :category rather than :category_id, so you need to use <%= error_tag f, :category %> instead, which is not explained in the book either, and it took me a while to figure out why it wasn’t being rendered.

It’s also not entirely clear to me whether just <%= error_tag f, :category %> is enough, or whether I might need a second error_tag with :category_id as well to cover all potential validation errors?

0 830 0

Where Next?

Popular Pragmatic Bookshelf topics Top

edruder
I thought that there might be interest in using the book with Rails 6.1 and Ruby 2.7.2. I’ll note what I needed to do differently here. ...
9 1173 1
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
15 1543 13
New
AleksandrKudashkin
On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
2 1425 11
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
1 1367 7
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
0 1148 3
New
fynn
This is as much a suggestion as a question, as a note for others. Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
0 1287 2
New
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
0 1727 1
New
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
0 1105 1
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
2 2083 9
New
s2k
Hi all, currently I wonder how the Tailwind colours work (or don’t work). For example, in app/views/layouts/application.html.erb I have...
2 1378 4
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
144 8502 50
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
160 3807 49
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
105 14440 47
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
200 3586 78
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
21 11128 7
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
21 4800 7
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
15 5398 1
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
37 3237 14
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
15 1138 15
New
Fl4m3Ph03n1x
Background Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
6 2202 3
New

Sub Categories: