“Phoenix in Action” is not new, but I can’t find solutions to those tasks included in this book (and I want to do them as part of the learning process as I’m new to programming):
The exercises:
Only allow bids that have a higher amount than the current high bid
Don’t allow bids on items after the item’s end_at date and time have passed
Only allow the creation of an item if a user is logged in
def delete_item(id) do
get_item(id)
|> @repo.delete()
end
AuctionWeb.ItemController (need some work)
def delete(_conn, %{"id" => id}) do
Auction.delete_item(id)
end
Routes
page_path GET / AuctionWeb.PageController :index
item_path GET /items AuctionWeb.ItemController :index
item_path GET /items/:id/edit AuctionWeb.ItemController :edit
item_path GET /items/new AuctionWeb.ItemController :new
item_path GET /items/:id AuctionWeb.ItemController :show
item_path POST /items AuctionWeb.ItemController :create
item_path PATCH /items/:id AuctionWeb.ItemController :update
PUT /items/:id AuctionWeb.ItemController :update
item_path DELETE /items/:id AuctionWeb.ItemController :delete
index.html.eex
<ul>
<%= link to: Routes.item_path(@conn, :new) do %>
add new
<% end %>
<%= for item <- @items do %>
<li><strong><%= link(item.title, to: Routes.item_path(@conn, :show, item)) %></strong>:
<%= item.description %> <%= item.user.username %>
<%= if @current_user == item.user do %>
| <%= link "Edit", to: Routes.item_path(@conn, :edit, item) %>
<%= link "Delete", to: Routes.item_path(@conn, :delete, item) %>
<% end %>
</li>
<% end %>
</ul>
The problem is - that link is not working. It just shows me the item.
I would also advise you join the slack channel to have easy access to help as you go forward: elixir-lang.slack.com (assuming you’re not already there, but I think it’s easier to troubleshoot these kinds of things there)
<%= link "Delete", to: Routes.item_path(@conn, :delete, item), method: :delete %>
# or, with confirmation
<%= link "Delete", to: Routes.item_path(@conn, :delete, item), method: :delete,
data: [confirm: gettext("Are you sure?")] %>