Peske

Peske

Hi i am new to phoenix and elixir and i am trying to make a textbox that insert 1 data into database and have some error :

== Compilation error in file lib/zivot_web/controllers/topic_controller.ex ==
** (KeyError) key :otp_app not found in: []
    (elixir) lib/keyword.ex:389: Keyword.fetch!/2
    lib/ecto/repo/supervisor.ex:62: Ecto.Repo.Supervisor.compile_config/2
    lib/zivot_web/controllers/topic_controller.ex:3: (module)
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:208: anonymous fn/4 in Kernel.ParallelCompiler.sp

repo.ex:

defmodule Zivot.Repo do
  use Ecto.Repo,
    otp_app: :zivot,
    adapter: Ecto.Adapters.Postgres
end

tabela.ex

defmodule Zivot.Tabela do
  use Ecto.Schema
  import Ecto.Changeset


  schema "topics" do
    field :topic, :string

    timestamps()
  end

  @doc false
#  def changeset(struct, params) do
#    struct
#    |> cast(params, [:topic])
#    |> validate_required([:topic])
#  end
end

defmodule ZivotWeb.Tabela do
  use Ecto.Schema
  import Ecto.Changeset
  def changeset(struct, params) do
    struct
    |> cast(params, [:topic])
    |> validate_required([:topic])
  end
end

defmodule ZivotWeb.TopicController do
  use ZivotWeb, :controller
  use Ecto.Repo
  alias Zivot.Tabela

 def new(conn, params) do
    struct = %Tabela{}
    params = %{}
    changeset = ZivotWeb.Tabela.changeset(struct,params)
    render conn, "new.html", changeset: changeset
  end
#  def create(conn, %{"tabela" => topic_params}) do
  #  changeset = ZivotWeb.Tabela.changeset(%Tabela{}, topic_params)
  #  case Repo.insert(changeset) do
  #    {:ok, post} ->
        #conn
      #  |> put_flash(:info, "Topic created")
      #  |> redirect(to: Routes.topic_path(conn, :index))
  #    {:error, changeset} ->
  #      render conn, "new.html", changeset: changeset
  #  end
  #end
end

new.html

<%= form_for @changeset, Routes.topic_path(@conn, :create), fn f -> %>
<%= text_input f, :topic %>
<%= submit "Save Topic" %>
<% end %>

Showing Posts 1 to 2

NobbZ

NobbZ

When ever you use Ecto.Repo, you must provide the :otp_app option.

kokolegorille

kokolegorille

Some files are misplaced…

defmodule ZivotWeb.Tabela do
  use Ecto.Schema
  import Ecto.Changeset
  def changeset(struct, params) do
    struct
    |> cast(params, [:topic])
    |> validate_required([:topic])
  end
end

This file does not belongs to the Web part, it belongs to Zivot part.

defmodule Zivot.Tabela do
  use Ecto.Schema
  import Ecto.Changeset


  schema "topics" do
    field :topic, :string

    timestamps()
  end

  @doc false
#  def changeset(struct, params) do
#    struct
#    |> cast(params, [:topic])
#    |> validate_required([:topic])
#  end
end

This file has no changeset, or commented, why?

And there is no context.

Can You provide the Phoenix version and the way You created the table?

There are generators that might help You building the application if You are a newcomer :slight_smile:

For example…

$ mix phx.new zivot
$ cd zivot
$ mix ecto.create
$ mix help | grep gen
mix clean              # Deletes generated application files
mix ecto.gen.migration # Generates a new migration for the repo
mix ecto.gen.repo      # Generates a new repository
mix local.phx          # Updates the Phoenix project generator locally
mix phx.gen.cert       # Generates a self-signed certificate for HTTPS testing
mix phx.gen.channel    # Generates a Phoenix channel
mix phx.gen.context    # Generates a context with functions around an Ecto schema
mix phx.gen.embedded   # Generates an embedded Ecto schema file
mix phx.gen.html       # Generates controller, views, and context for an HTML resource
mix phx.gen.json       # Generates controller, views, and context for a JSON resource
mix phx.gen.presence   # Generates a Presence tracker
mix phx.gen.schema     # Generates an Ecto schema and migration file
mix phx.gen.secret     # Generates a secret
$ mix help phx.gen.html
— All posts loaded —

Where Next? Top

Trending in Questions Top

itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
rlipscombe
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used? I’ve got two Github accoun...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews