Notesclub

Blog: Posts

exercises/blog_posts.livemd

Blog: Posts

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue SQL DrillsBookSearch: Authors

Blog: Posts

You’re going to create the Posts resource in your Blog project.

Blog posts should have a title, subtitle, and content. It should also have relevant timestamp information.

classDiagram
  class Post {
    title: :string
    subtitle: :string
    content: :text
  }

You may use Phoenix Generators or create the Controller, Context, and other infrastructure for the post resource or you may create it all from scratch.

Example Solution

Generate the resource.

$ mix phx.gen.html Posts Post posts title:string subtitle:string content:text
$ mix ecto.migrate

Then add the resource to router.ex.

scope "/", BlogWeb do
  pipe_through :browser

  get "/", PageController, :index
  resources "/posts", PostController
end

Alternatively we can define every route individually.

scope "/", BlogWeb do
  pipe_through :browser

  get "/", PageController, :index
  get "/posts", PostController, :index
  get "/posts/new", PostController, :new
  post "/posts", PostController, :create
  get "/posts/:id", PostController, :show
  get "/posts/:id/edit", PostController, :edit
  put "/posts/:id", PostController, :update
  patch "/posts/:id", PostController, :update
  delete "/posts/:id", PostController, :delete
end

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Blog: Posts exercise"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue SQL DrillsBookSearch: Authors