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
|
||||
Loading…
Add table
Add a link
Reference in a new issue