bharani91 / ex-shop

Digital goods shop & blog created using Elixir (Phoenix framework)

Home Page:https://www.authenticpixels.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

new product errors?

niccolox opened this issue · comments

hey, cool project

getting an error creating first product, have a new category already created

new blogs and pages works ok

[error] #PID<0.584.0> running Ap.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /admin/products/new
** (exit) an exception was raised:
    ** (KeyError) key :model not found in: %Phoenix.HTML.Form{data: %Ap.Variant{__meta__: #Ecto.Schema.Metadata<:built, "variants">, delete: nil, description: nil, id: nil, inserted_at: nil, price: nil, product: #Ecto.Association.NotLoaded<association :product is not loaded>, product_id: nil, purchase_url: nil, title: nil, updated_at: nil}, errors: [], hidden: [], id: "product_variants_0", impl: Phoenix.HTML.FormData.Ecto.Changeset, index: 0, name: "product[variants][0]", options: [], params: %{}, source: #Ecto.Changeset<action: nil, changes: %{}, errors: [title: {"can't be blank", []}, description: {"can't be blank", []}, price: {"can't be blank", []}, purchase_url: {"can't be blank", []}], data: #Ap.Variant<>, valid?: false>}
        (ap) web/templates/admin/product/variant_fields.html.eex:25: anonymous fn/1 in Ap.Admin.ProductView.variant_fields.html/1
        (phoenix_html) lib/phoenix_html/form.ex:274: anonymous fn/2 in Phoenix.HTML.Form.inputs_for/4
        (elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2
        (phoenix_html) lib/phoenix_html/form.ex:272: Phoenix.HTML.Form.inputs_for/4
        (ap) web/templates/admin/product/variant_fields.html.eex:1: Ap.Admin.ProductView."variant_fields.html"/1
        (phoenix) lib/phoenix/view.ex:335: Phoenix.View.render_to_iodata/3
        (phoenix) lib/phoenix/view.ex:342: Phoenix.View.render_to_string/3
        (ap) web/views/admin/product_view.ex:11: Ap.Admin.ProductView.link_to_add_variant/0
        (ap) web/templates/admin/product/form.html.eex:155: anonymous fn/2 in Ap.Admin.ProductView.form.html/1
        (phoenix_html) lib/phoenix_html/form.ex:236: Phoenix.HTML.Form.form_for/4
        (ap) web/templates/admin/product/form.html.eex:1: Ap.Admin.ProductView."form.html"/1
        (ap) web/templates/admin/product/new.html.eex:7: Ap.Admin.ProductView."new.html"/1
        (ap) web/templates/layout/admin.html.eex:23: Ap.LayoutView."admin.html"/1
        (phoenix) lib/phoenix/view.ex:335: Phoenix.View.render_to_iodata/3
        (phoenix) lib/phoenix/controller.ex:642: Phoenix.Controller.do_render/4
        (ap) web/controllers/admin/product_controller.ex:1: Ap.Admin.ProductController.action/2
        (ap) web/controllers/admin/product_controller.ex:1: Ap.Admin.ProductController.phoenix_controller_pipeline/2
        (ap) lib/ap/endpoint.ex:1: Ap.Endpoint.instrument/4
        (ap) lib/phoenix/router.ex:261: Ap.Router.dispatch/2
        (ap) web/router.ex:1: Ap.Router.do_call/2

Thanks for pointing this out. Not sure how I missed this. I should have used variant.data to get the changeset source data instead of using variant.model.

Just rolled out a fix for this.

still getting errors

[error] #PID<0.465.0> running Ap.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /admin/products
** (exit) an exception was raised:
    ** (KeyError) key :model not found in: %Phoenix.HTML.Form{data: %Ap.Variant{__meta__: #Ecto.Schema.Metadata<:built, "variants">, delete: nil, description: nil, id: nil, inserted_at: nil, price: nil, product: #Ecto.Association.NotLoaded<association :product is not loaded>, product_id: nil, purchase_url: nil, title: nil, updated_at: nil}, errors: [purchase_url: {"can't be blank", []}], hidden: [], id: "product_variants_0", impl: Phoenix.HTML.FormData.Ecto.Changeset, index: 0, name: "product[variants][0]", options: [], params: %{"description" => "prod4", "price" => "34", "purchase_url" => nil, "title" => "prodd22"}, source: #Ecto.Changeset<action: :insert, changes: %{description: "prod4", price: 34, title: "prodd22"}, errors: [purchase_url: {"can't be blank", []}], data: #Ap.Variant<>, valid?: false>}
        (ap) web/templates/admin/product/form.html.eex:146: anonymous fn/1 in Ap.Admin.ProductView.form.html/1
        (phoenix_html) lib/phoenix_html/form.ex:274: anonymous fn/2 in Phoenix.HTML.Form.inputs_for/4
        (elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2
        (phoenix_html) lib/phoenix_html/form.ex:272: Phoenix.HTML.Form.inputs_for/4
        (ap) web/templates/admin/product/form.html.eex:122: anonymous fn/2 in Ap.Admin.ProductView.form.html/1
        (phoenix_html) lib/phoenix_html/form.ex:236: Phoenix.HTML.Form.form_for/4
        (ap) web/templates/admin/product/form.html.eex:1: Ap.Admin.ProductView."form.html"/1
        (ap) web/templates/admin/product/new.html.eex:7: Ap.Admin.ProductView."new.html"/1
        (ap) web/templates/layout/admin.html.eex:23: Ap.LayoutView."admin.html"/1
        (phoenix) lib/phoenix/view.ex:335: Phoenix.View.render_to_iodata/3
        (phoenix) lib/phoenix/controller.ex:642: Phoenix.Controller.do_render/4
        (ap) web/controllers/admin/product_controller.ex:1: Ap.Admin.ProductController.action/2
        (ap) web/controllers/admin/product_controller.ex:1: Ap.Admin.ProductController.phoenix_controller_pipeline/2
        (ap) lib/ap/endpoint.ex:1: Ap.Endpoint.instrument/4
        (ap) lib/phoenix/router.ex:261: Ap.Router.dispatch/2
        (ap) web/router.ex:1: Ap.Router.do_call/2
        (ap) lib/plug/error_handler.ex:64: Ap.Router.call/2
        (ap) lib/ap/endpoint.ex:1: Ap.Endpoint.phoenix_pipeline/1
        (ap) lib/plug/debugger.ex:123: Ap.Endpoint."call (overridable 3)"/2
        (ap) lib/ap/endpoint.ex:1: Ap.Endpoint.call/2

I can see product form now but when I submit get errors

shouldn't there be a migration?

I haven't tried to drop db yet

tried mix ecto.drop && mix ecto.create and get this

[error] #PID<0.437.0> running Ap.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
    ** (Postgrex.Error) ERROR (undefined_table): relation "product_categories" does not exist
        (ecto) lib/ecto/adapters/sql.ex:413: Ecto.Adapters.SQL.execute_and_cache/7
        (ecto) lib/ecto/repo/queryable.ex:127: Ecto.Repo.Queryable.execute/5
        (ecto) lib/ecto/repo/queryable.ex:40: Ecto.Repo.Queryable.all/4
        (ap) lib/utils/default_assigns.ex:10: Ap.Plugs.DefaultAssigns.call/2
        (ap) web/router.ex:24: Ap.Router.default_assigns/2
        (ap) web/router.ex:1: Ap.Router.match_route/4
        (ap) web/router.ex:1: Ap.Router.do_call/2
        (ap) lib/plug/error_handler.ex:64: Ap.Router.call/2
        (ap) lib/ap/endpoint.ex:1: Ap.Endpoint.phoenix_pipeline/1
        (ap) lib/plug/debugger.ex:123: Ap.Endpoint."call (overridable 3)"/2
        (ap) lib/ap/endpoint.ex:1: Ap.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4