wolfiton

wolfiton

Hi everyone,

I am getting an error when i try to add a select in a nested form

The error no function clause matching in Keyword.pop/3

My select code:

<div class="field">
  <%= label f, :category, class: "label" %>
  <div class="control">

    <%= select f, :category_id, @categories, fn cf -> %>
    IO.inspect(@categories)
  </div>
  <p class="help is-danger"><%= error_tag cf, :category %></p>
  <% end %>
</div>

Update link to form as suggested by @benwilson512

https://github.com/wolfiton/blog_api/blob/master/lib/blog_api_web/templates/article/form.html.eex

Update error trace

[info] GET /articles/new
[]
[debug] Processing with BlogApiWeb.ArticleController.new/2
  Parameters: %{}
  Pipelines: [:browser]
[debug] QUERY OK source="categories" db=2.3ms
SELECT c0."id", c0."name", c0."slug", c0."inserted_at", c0."updated_at" FROM "categories" AS c0 []
[info] Sent 500 in 166ms
[error] #PID<0.840.0> running BlogApiWeb.Endpoint (connection #PID<0.839.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /articles/new
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in Keyword.pop/3
        (elixir) lib/keyword.ex:977: Keyword.pop(#Function<2.44023343/1 in BlogApiWeb.ArticleView."form.html"/1>, :value, nil)
        (phoenix_html) lib/phoenix_html/form.ex:1117: Phoenix.HTML.Form.selected/3
        (phoenix_html) lib/phoenix_html/form.ex:1099: Phoenix.HTML.Form.select/4
        (blog_api) lib/blog_api_web/templates/article/form.html.eex:29: anonymous fn/2 in BlogApiWeb.ArticleView."form.html"/1
        (phoenix_html) lib/phoenix_html/form.ex:377: Phoenix.HTML.Form.form_for/4
        (blog_api) lib/blog_api_web/templates/article/form.html.eex:1: BlogApiWeb.ArticleView."form.html"/1
        (blog_api) lib/blog_api_web/templates/article/new.html.eex:3: BlogApiWeb.ArticleView."new.html"/1
        (blog_api) lib/blog_api_web/templates/layout/app.html.eex:15: BlogApiWeb.LayoutView."app.html"/1
        (phoenix) lib/phoenix/view.ex:410: Phoenix.View.render_to_iodata/3
        (phoenix) lib/phoenix/controller.ex:729: Phoenix.Controller.__put_render__/5
        (phoenix) lib/phoenix/controller.ex:746: Phoenix.Controller.instrument_render_and_send/4
        (blog_api) lib/blog_api_web/controllers/article_controller.ex:1: BlogApiWeb.ArticleController.action/2
        (blog_api) lib/blog_api_web/controllers/article_controller.ex:1: BlogApiWeb.ArticleController.phoenix_controller_pipeline/2
        (phoenix) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2
        (blog_api) lib/blog_api_web/endpoint.ex:1: BlogApiWeb.Endpoint.plug_builder_call/2
        (blog_api) lib/plug/debugger.ex:122: BlogApiWeb.Endpoint."call (overridable 3)"/2
        (blog_api) lib/blog_api_web/endpoint.ex:1: BlogApiWeb.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy) /home/dan/Codes/blog_api/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
        (cowboy) /home/dan/Codes/blog_api/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3

Update article controller
https://github.com/wolfiton/blog_api/blob/master/lib/blog_api_web/controllers/article_controller.ex
Update migrations for articles and categories
https://github.com/wolfiton/blog_api/blob/master/priv/repo/migrations/20191203154052_create_articles.exs
https://github.com/wolfiton/blog_api/blob/master/priv/repo/migrations/20191213160415_create_categories.exs

Schemas and contexts

https://github.com/wolfiton/blog_api/blob/master/lib/blog_api/blog/article.ex

https://github.com/wolfiton/blog_api/blob/master/lib/blog_api/categories/category.ex

https://github.com/wolfiton/blog_api/blob/master/lib/blog_api/blog.ex

https://github.com/wolfiton/blog_api/blob/master/lib/blog_api/categories.ex

Also if there are any suggestions for the rest of my code the full code here https://github.com/wolfiton/blog_api
Thanks in advance

Showing Posts 1 to 7

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Please provide the full stack trace of the error, and it would probably help to link to the form within that code base.

wolfiton

wolfiton OP

Thanks @benwilson512 for the suggestion I added more info.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe
wolfiton

wolfiton OP

OK so I use the nested without passing a fn then?

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I’m not really sure I understand why you need a nested form at all. :category_id is a field of the changeset. Nested forms are necessary when you are editing a value AND an associated (or embedded) value. Your form only messes with the top level changeset.

Either way, select does not create a nested form, you want inputs_for for that.

wolfiton

wolfiton OP

Thanks I will check it out

Also to answer to you questions

I thought that this is the best way to achive what i wanted. But if it is not then please recommend a better way I have created this project to learn and understand phoenix so i am very open to any suggestions you might have.

Thanks again for helping me with this.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

If what you want is to edit the category_id field, just treat it like the :title field.

<%= select f, :category_id, @categories %>
<p class="help is-danger"><%= error_tag f, :category %></p>
— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews