now you can actually create tags
This commit is contained in:
parent
80084f0952
commit
86b296dddf
8 changed files with 86 additions and 0 deletions
48
app/controllers/tags_controller.rb
Normal file
48
app/controllers/tags_controller.rb
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
class TagsController < ApplicationController
|
||||
allow_unauthenticated_access only: %i[ index show ]
|
||||
before_action :set_tag, only: %i[ show edit update destroy ]
|
||||
def index
|
||||
@tags = Tag.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@tag = Tag.new
|
||||
end
|
||||
|
||||
def create
|
||||
@tag = Tag.new(tag_params)
|
||||
if @tag.save
|
||||
redirect_to @tag
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @tag.update(tag_params)
|
||||
redirect_to @tag
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@tag.destroy
|
||||
redirect_to tags_path
|
||||
end
|
||||
|
||||
private
|
||||
def set_tag
|
||||
@tag = Tag.find(params[:id])
|
||||
end
|
||||
|
||||
def tag_params
|
||||
params.expect(tag: [ :name ])
|
||||
end
|
||||
end
|
||||
|
|
@ -34,6 +34,7 @@
|
|||
<%= link_to "Login", new_session_path unless authenticated? %>
|
||||
<%= link_to "Clips", clips_path %>
|
||||
<%= link_to "Categories", categories_path %>
|
||||
<%= link_to "Tags", tags_path %>
|
||||
</nav>
|
||||
<main>
|
||||
<%= yield %>
|
||||
|
|
|
|||
10
app/views/tags/_form.html.erb
Normal file
10
app/views/tags/_form.html.erb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<%= form_with model: tag do |form| %>
|
||||
<div>
|
||||
<%= form.label :name %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
4
app/views/tags/edit.html.erb
Normal file
4
app/views/tags/edit.html.erb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<h1>Edit tag</h1>
|
||||
|
||||
<%= render "form", tag: @tag %>
|
||||
<%= link_to "Cancel", @tag %>
|
||||
9
app/views/tags/index.html.erb
Normal file
9
app/views/tags/index.html.erb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<h1>Tags</h1>
|
||||
|
||||
<%= link_to "New tag", new_tag_path if authenticated? %>
|
||||
|
||||
<ul id="tags">
|
||||
<% @tags.each do |tag| %>
|
||||
<li><%= link_to tag.name, tag %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
4
app/views/tags/new.html.erb
Normal file
4
app/views/tags/new.html.erb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<h1>New tag</h1>
|
||||
|
||||
<%= render "form", tag: @tag %>
|
||||
<%= link_to "Cancel", tags_path %>
|
||||
9
app/views/tags/show.html.erb
Normal file
9
app/views/tags/show.html.erb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<% cache @tag do %>
|
||||
<h1><%= @tag.name %></h1>
|
||||
<% end %>
|
||||
|
||||
<%= link_to "Back", tags_path%>
|
||||
<% if authenticated? %>
|
||||
<%= link_to "Edit", edit_tag_path(@tag) %>
|
||||
<%= button_to "Delete", @tag, method: :delete, data: { turbo_confirm: "Are you sure?" } %>
|
||||
<% end %>
|
||||
Loading…
Add table
Add a link
Reference in a new issue