Skip to content

Commit a3e1e8b

Browse files
committed
Add in topics
1 parent cf9e2ab commit a3e1e8b

File tree

10 files changed

+102
-53
lines changed

10 files changed

+102
-53
lines changed

app/controllers/topics_controller.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
class TopicsController < ApplicationController
22
before_action :set_topic, only: %i[show edit update destroy]
3-
before_action :authenticate_user!
4-
before_action :authorize_user!, only: %i[edit update destroy]
53

64
def index
75
@topics = Topic.all
@@ -56,8 +54,4 @@ def set_topic
5654
def topic_params
5755
params.require(:topic).permit(:title, :description, :language_id, :provider_id, :archived)
5856
end
59-
60-
def authorize_user!
61-
redirect_to topics_path, alert: "You are not authorized to perform this action." unless current_user == @topic.provider.user
62-
end
6357
end

app/views/languages/new.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<% content_for :title, "New language" %>
2-
32
<section id="basic-vertical-layouts">
43
<div class="row match-height">
54
<div class="col-md-6 col-12">

app/views/layouts/_sidebar.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<div id="sidebar">
32
<div class="sidebar-wrapper active">
43
<div class="sidebar-header position-relative">
@@ -59,10 +58,10 @@
5958
</li>
6059

6160
<li class="sidebar-item">
62-
<a href="ui-file-uploader.html" class="sidebar-link">
61+
<%= link_to topics_path, class: "sidebar-link" do %>
6362
<i class="bi bi-tags-fill"></i>
6463
<span>Topics</span>
65-
</a>
64+
<% end %>
6665
</li>
6766

6867
<li class="sidebar-item">

app/views/topics/_form.html.erb

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,40 @@
1111
</div>
1212
<% end %>
1313

14-
<div class="col-md-4">
15-
<div class="form-group">
16-
<%= form.label :title, style: "display: block" %>
17-
<%= form.text_field :title, id: "basicInput", class: "form-control", autofocus: true %>
14+
<div class="row">
15+
<div class="col-md-4">
16+
<div class="form-group">
17+
<%= form.label :title, style: "display: block" %>
18+
<%= form.text_field :title, id: "basicInput", class: "form-control", autofocus: true %>
19+
</div>
1820
</div>
19-
</div>
2021

21-
<div class="col-md-4">
22-
<div class="form-group">
23-
<%= form.label :description, style: "display: block" %>
24-
<%= form.text_area :description, id: "basicInput", class: "form-control" %>
22+
<div class="col-md-4">
23+
<div class="form-group">
24+
<%= form.label :description, style: "display: block" %>
25+
<%= form.text_area :description, id: "basicInput", class: "form-control" %>
26+
</div>
2527
</div>
26-
</div>
2728

28-
<div class="col-md-4">
29-
<div class="form-group">
30-
<%= form.label :language_id, style: "display: block" %>
31-
<%= form.collection_select :language_id, Language.all, :id, :name, id: "basicInput", class: "form-control" %>
29+
<div class="col-md-4">
30+
<div class="form-group">
31+
<%= form.label :language_id, style: "display: block" %>
32+
<%= form.collection_select :language_id, Language.all, :id, :name, {}, { id: "basicInput", class: "form-control" } %>
33+
</div>
3234
</div>
33-
</div>
3435

35-
<div class="col-md-4">
36-
<div class="form-group">
37-
<%= form.label :provider_id, style: "display: block" %>
38-
<%= form.collection_select :provider_id, Provider.all, :id, :name, id: "basicInput", class: "form-control" %>
36+
<div class="col-md-4">
37+
<div class="form-group">
38+
<%= form.label :provider_id, style: "display: block" %>
39+
<%= form.collection_select :provider_id, Provider.all, :id, :name, {}, { id: "basicInput", class: "form-control" } %>
40+
</div>
3941
</div>
40-
</div>
4142

42-
<div class="col-md-4">
43-
<div class="form-group">
44-
<%= form.label :archived, style: "display: block" %>
45-
<%= form.check_box :archived, id: "basicInput", class: "form-control" %>
43+
<div class="col-md-4">
44+
<div class="form-group">
45+
<%= form.label :archived, "Archived", for: "checkbox1", style: "display: block" %>
46+
<%= form.check_box :archived, { id: "checkbox1", class: "form-check-input", checked: false } %>
47+
</div>
4648
</div>
4749
</div>
4850

app/views/topics/new.html.erb

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
<% content_for :title, "New Topic" %>
22

3-
<h1>New Topic</h1>
4-
5-
<%= render "form", topic: @topic %>
6-
7-
<div class="mt-4">
8-
<%= link_to "Back to topics", topics_path %>
9-
</div>
3+
<section id="multiple-column-form">
4+
<div class="row match-height">
5+
<div class="col-12">
6+
<div class="card">
7+
<div class="card-header">
8+
<h4>Create New Topic</h4>
9+
</div>
10+
<div class="card-content">
11+
<div class="card-body">
12+
<p>Topics should ... Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut
13+
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
14+
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
15+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
16+
laborum.</p>
17+
<%= render "form", topic: @topic %>
18+
</div>
19+
</div>
20+
</div>
21+
</div>
22+
</div>
23+
</section>
File renamed without changes.

db/schema.rb

Lines changed: 22 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/factories/topics.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FactoryBot.define do
2+
factory :topic do
3+
title { "Default Title" }
4+
description { "Default Description" }
5+
archived { false }
6+
association :language
7+
association :provider
8+
end
9+
end

spec/models/topic_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
it { should belong_to(:language) }
99
it { should belong_to(:provider) }
10-
it { should have_many(:taggings) }
11-
it { should have_many(:training_resources) }
10+
# it { should have_many(:taggings) }
11+
# it { should have_many(:training_resources) }
1212

1313
describe "scopes" do
1414
it "includes archived topics" do

spec/requests/topics_spec.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,26 @@
77
sign_in(user)
88
end
99

10-
let(:valid_attributes) { { title: "New Topic", description: "Topic description", language_id: 1, provider_id: 1, archived: false } }
11-
let(:invalid_attributes) { { title: "", language_id: nil, provider_id: nil } }
10+
let(:language) { FactoryBot.create(:language) }
11+
let(:provider) { FactoryBot.create(:provider) }
12+
let(:valid_attributes) do
13+
{
14+
title: "My Topic Title",
15+
description: "A valid description",
16+
language_id: language.id,
17+
provider_id: provider.id,
18+
archived: false,
19+
}
20+
end
21+
let(:invalid_attributes) do
22+
{
23+
title: "",
24+
description: "A valid description",
25+
language_id: language.id,
26+
provider_id: provider.id,
27+
archived: false,
28+
}
29+
end
1230

1331
describe "GET /index" do
1432
it "renders a successful response" do

0 commit comments

Comments
 (0)