concept item in category elixir

This is an excerpt from Manning's book Phoenix in Action.
You can think of a list in Elixir as similar to an array in other languages, or as simply a list of items that may or may not be similar types. Depending on the language you’re most familiar with, it may even have similar syntax.
An Elixir list is a list of items contained in a single type (you’ll see in a moment that they’re more than that, though). Lists can contain any other Elixir types (even mixed types) and can even contain references to other lists.
iex(1)> list = [1, 2] [1, 2] iex(2)> [:numbers, "for example", list] [:numbers, "for example", [1, 2]]The interesting thing about lists in Elixir is that they’re linked lists. Each item in a list has an internal pointer to the next item in the list (see figure 2.5). You’ll never interact, see, or really know anything about that internal pointer—just trust that it’s there. Practically, this means that a number of typical operations are fast and memory-kind. It’s efficient to add items to the beginning of a list, but adding items to the end of a list can get slower as the list grows in size.
Listing 9.1. Defining a set of RESTful routes for items
defmodule AuctionWeb.Router do use AuctionWeb, :router pipeline :browser do # ... end scope "/", AuctionWeb do pipe_through :browser # Use the default browser stack get "/items", ItemController, :index #1 get "/items/new", ItemController, :new post "/items", ItemController, :create get "/items/:id", ItemController, :show get "/items/:id/edit", ItemController, :edit patch "/items/:id", ItemController, :update put "/items/:id", ItemController, :update delete "/items/:id", ItemController, :delete end end
As explained in chapter 6, the view passes on the Plug.Conn struct along with any other assigns you’ve declared (like @items) to the correct template. Figure 9.3 illustrates what we discussed in chapter 6. You declared the “correct” template when you called render conn, "index.html", items: items in AuctionWeb.ItemController.index/2—it will attempt to render index.html.
You’re replicating (for now) the page you modified in chapter 6, so you can copy the EEx code from that file to this new one. This template will simply list the items for auction in your database. Create a new file at auction_umbrella/apps/auction_web/lib/auction_web/templates/item/index.html.eex and key in the following code.
Listing 9.7. Listing the items in the database
<ul> <%= for item <- @items do %> #1 <li><strong><%= item.title %></strong>: <%= item.description %></li> <% end %> </ul>If you start up the Phoenix server with mix phx.server and navigate to http://localhost:4000/items, you’ll see your list of items, just like in chapter 6.
If the Auction.Item.changeset/2 function determines that the changeset is invalid, Auction.insert_item/1 will return {:error, item}, with item being the changeset with an errors attribute. In the case of an invalid item, you want to rerender the form and notify the user of any errors so they can fix them. You need to make changes in two places: AuctionWeb.ItemController.create/2 and .../templates/item/new .html.eex. In the former, you need to handle the error case and render the form again. In the latter, you need to display any relevant errors.
You can view your items in a browser, and you can create and modify items inside an IEx session. What you need now is a way to create and modify items in a browser. Most websites provide a way for users or admins to do that kind of thing through a web form. In this section, you’ll create a web form that allows you to create an item.