diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb new file mode 100644 index 00000000..9999ecb2 --- /dev/null +++ b/app/controllers/topics_controller.rb @@ -0,0 +1,57 @@ +class TopicsController < ApplicationController + before_action :set_topic, only: %i[show edit update destroy] + + def index + @topics = Topic.all + end + + def show + end + + def new + @topic = Topic.new + end + + def edit + end + + def create + @topic = Topic.new(topic_params) + + respond_to do |format| + if @topic.save + format.html { redirect_to @topic, notice: "Topic was successfully created." } + else + format.html { render :new, status: :unprocessable_entity } + end + end + end + + def update + respond_to do |format| + if @topic.update(topic_params) + format.html { redirect_to @topic, notice: "Topic was successfully updated." } + else + format.html { render :edit, status: :unprocessable_entity } + end + end + end + + def destroy + @topic.destroy! + + respond_to do |format| + format.html { redirect_to topics_path, status: :see_other, notice: "Topic was successfully destroyed." } + end + end + + private + + def set_topic + @topic = Topic.find(params[:id]) + end + + def topic_params + params.require(:topic).permit(:title, :description, :language_id, :provider_id, :archived) + end +end diff --git a/app/models/topic.rb b/app/models/topic.rb new file mode 100644 index 00000000..c9fd5218 --- /dev/null +++ b/app/models/topic.rb @@ -0,0 +1,12 @@ +class Topic < ApplicationRecord + belongs_to :language + belongs_to :provider + has_many :taggings + has_many :training_resources + + validates :title, presence: true + validates :language_id, presence: true + validates :provider_id, presence: true + + scope :archived, -> { where(archived: true) } +end diff --git a/app/views/languages/new.html.erb b/app/views/languages/new.html.erb index b9afd7a9..e86e4304 100644 --- a/app/views/languages/new.html.erb +++ b/app/views/languages/new.html.erb @@ -1,5 +1,4 @@ <% content_for :title, "New language" %> -
diff --git a/app/views/layouts/_sidebar.html.erb b/app/views/layouts/_sidebar.html.erb index 89ac0ea1..c7912be5 100644 --- a/app/views/layouts/_sidebar.html.erb +++ b/app/views/layouts/_sidebar.html.erb @@ -1,4 +1,3 @@ -