diff --git a/app/controllers/languages_controller.rb b/app/controllers/admin/languages_controller.rb
similarity index 83%
rename from app/controllers/languages_controller.rb
rename to app/controllers/admin/languages_controller.rb
index 6e68bac..a0cd86f 100644
--- a/app/controllers/languages_controller.rb
+++ b/app/controllers/admin/languages_controller.rb
@@ -1,4 +1,4 @@
-class LanguagesController < ApplicationController
+class Admin::LanguagesController < ApplicationController
def index
@languages = Language.all
@@ -12,7 +12,7 @@ class LanguagesController < ApplicationController
@language = Language.new(language_params)
if @language.save
flash[:notice] = "Language successfully created."
- redirect_to languages_path
+ redirect_to admin_languages_path
else
render :new, status: :unprocessable_entity
end
@@ -26,7 +26,7 @@ class LanguagesController < ApplicationController
@language = Language.find_by_id(params[:id])
if @language.update(language_params)
flash[:notice] = "Language successfully updated."
- redirect_to languages_path
+ redirect_to admin_languages_path
else
render :edit, status: :unprocessable_entity
end
@@ -36,7 +36,7 @@ class LanguagesController < ApplicationController
@language = Language.find_by_id(params[:id])
if @language.destroy
flash[:notice] = "Language successfully deleted."
- redirect_to languages_path
+ redirect_to admin_languages_path
else
render :index, status: :not_modified
end
diff --git a/app/views/languages/_errors.html.erb b/app/views/admin/languages/_errors.html.erb
similarity index 100%
rename from app/views/languages/_errors.html.erb
rename to app/views/admin/languages/_errors.html.erb
diff --git a/app/views/languages/_form.html.erb b/app/views/admin/languages/_form.html.erb
similarity index 68%
rename from app/views/languages/_form.html.erb
rename to app/views/admin/languages/_form.html.erb
index e325c75..639a177 100644
--- a/app/views/languages/_form.html.erb
+++ b/app/views/admin/languages/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_for language do |f| %>
+<%= form_for [:admin, language] do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
diff --git a/app/views/languages/create.html.erb b/app/views/admin/languages/create.html.erb
similarity index 100%
rename from app/views/languages/create.html.erb
rename to app/views/admin/languages/create.html.erb
diff --git a/app/views/languages/destroy.html.erb b/app/views/admin/languages/destroy.html.erb
similarity index 100%
rename from app/views/languages/destroy.html.erb
rename to app/views/admin/languages/destroy.html.erb
diff --git a/app/views/admin/languages/edit.html.erb b/app/views/admin/languages/edit.html.erb
new file mode 100644
index 0000000..7794876
--- /dev/null
+++ b/app/views/admin/languages/edit.html.erb
@@ -0,0 +1,5 @@
+<%= render "admin/languages/errors", language: @language %>
+
+
Edit Language
+
+<%= render "admin/languages/form", language: @language %>
diff --git a/app/views/languages/index.html.erb b/app/views/admin/languages/index.html.erb
similarity index 58%
rename from app/views/languages/index.html.erb
rename to app/views/admin/languages/index.html.erb
index cc3a333..bdf6a66 100644
--- a/app/views/languages/index.html.erb
+++ b/app/views/admin/languages/index.html.erb
@@ -7,9 +7,9 @@
<% @languages.each do |language| %>
<%= language.name %> |
- <%= link_to "Edit", edit_language_path(language) %> |
+ <%= link_to "Edit", edit_admin_language_path(language) %> |
| |
- <%= link_to "Delete", language_path(language), data: { turbo_method: :delete,
+ | <%= link_to "Delete", admin_language_path(language), data: { turbo_method: :delete,
turbo_confirm: "Are you sure?" } %> |
<% end %>
@@ -17,4 +17,4 @@
-<%= link_to "New Language", new_language_path %>
+<%= link_to "New Language", new_admin_language_path %>
diff --git a/app/views/admin/languages/new.html.erb b/app/views/admin/languages/new.html.erb
new file mode 100644
index 0000000..b25507e
--- /dev/null
+++ b/app/views/admin/languages/new.html.erb
@@ -0,0 +1,5 @@
+<%= render "admin/languages/errors", language: @language %>
+
+New Language
+
+<%= render "admin/languages/form", language: @language %>
diff --git a/app/views/languages/show.html.erb b/app/views/admin/languages/show.html.erb
similarity index 100%
rename from app/views/languages/show.html.erb
rename to app/views/admin/languages/show.html.erb
diff --git a/app/views/languages/update.html.erb b/app/views/admin/languages/update.html.erb
similarity index 100%
rename from app/views/languages/update.html.erb
rename to app/views/admin/languages/update.html.erb
diff --git a/app/views/application/_partsofspeech.html.erb b/app/views/application/_partsofspeech.html.erb
index 5354fee..36e9fac 100644
--- a/app/views/application/_partsofspeech.html.erb
+++ b/app/views/application/_partsofspeech.html.erb
@@ -1,4 +1,5 @@
Parts of Speech
+
Part of Speech |
@@ -11,4 +12,3 @@
<% end %>
-
diff --git a/app/views/languages/edit.html.erb b/app/views/languages/edit.html.erb
deleted file mode 100644
index 13ba0c1..0000000
--- a/app/views/languages/edit.html.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-<%= render "languages/errors", language: @language %>
-
-Edit Language
-
-<%= render "languages/form", language: @language %>
diff --git a/app/views/languages/new.html.erb b/app/views/languages/new.html.erb
deleted file mode 100644
index 38ea897..0000000
--- a/app/views/languages/new.html.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-<%= render "languages/errors", language: @language %>
-
-New Language
-
-<%= render "languages/form", language: @language %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 13b5356..1825218 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -17,7 +17,7 @@
<%= link_to "Dictionary", dictionary_index_path %>
<% if user_signed_in? %>
|
- <%= link_to "Languages", languages_path %>
+ <%= link_to "Languages", admin_languages_path %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 30c2433..24361b3 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,9 +1,11 @@
Rails.application.routes.draw do
devise_for :users
#get 'dictionary/index'
- resources :dictionary, only: [:index, :show]
+ resources :dictionary, only: [:index, :show, :create]
resources :words, only: [:index, :show]
- resources :languages
+ namespace :admin do
+ resources :languages
+ end
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
diff --git a/spec/requests/language_spec.rb b/spec/requests/language_spec.rb
index 847b2b3..64b626d 100644
--- a/spec/requests/language_spec.rb
+++ b/spec/requests/language_spec.rb
@@ -4,59 +4,59 @@ RSpec.describe "Languages", type: :request do
describe "GET :index" do
it "returns http success" do
- get "/languages/"
+ get "/admin/languages/"
expect(response).to have_http_status(:success)
end
it "lists all languages" do
language = FactoryBot.create(:language)
- get "/languages/"
+ get "/admin/languages/"
expect(response.body).to include(language.name)
end
it "has a new-language link" do
- get "/languages/"
- expect(response.body).to have_selector(%(a[href="#{new_language_path}"]))
+ get "/admin/languages/"
+ expect(response.body).to have_selector(%(a[href="#{new_admin_language_path}"]))
end
it "has an edit button" do
language = FactoryBot.create(:language)
- get "/languages/"
+ get "/admin/languages/"
expect(response.body).to have_link("Edit")
end
it "has a delete button" do
language = FactoryBot.create(:language)
- get "/languages/"
+ get "/admin/languages/"
expect(response.body).to have_link("Delete")
end
end
describe "GET :new" do
it "returns http success" do
- get "/languages/new"
+ get "/admin/languages/new"
expect(response).to have_http_status(:success)
end
it "has a form for a new language" do
- get "/languages/new"
+ get "/admin/languages/new"
expect(response.body).to have_selector(%(input[name="language[name]"]))
end
end
describe "POST :create" do
- it "redirect to languages_path on success" do
- post "/languages", params: { language: { name: "Test Name" } }
- expect(response).to redirect_to(languages_path)
+ it "redirect to admin_languages_path on success" do
+ post "/admin/languages", params: { language: { name: "Test Name" } }
+ expect(response).to redirect_to(admin_languages_path)
end
it "creates a new language" do
- post "/languages", params: { language: { name: "Test Name" } }
+ post "/admin/languages", params: { language: { name: "Test Name" } }
expect(Language.count).to eq(1)
end
it "requires a name for a new language" do
- post "/languages", params: { language: { name: nil } }
+ post "/admin/languages", params: { language: { name: nil } }
expect(response).to have_http_status(:unprocessable_entity)
end
end
@@ -64,7 +64,7 @@ RSpec.describe "Languages", type: :request do
describe "GET :edit" do
before :each do
@language = FactoryBot.create(:language)
- get "/languages/#{@language.id}/edit"
+ get "/admin/languages/#{@language.id}/edit"
end
it "returns http success" do
@@ -83,13 +83,13 @@ RSpec.describe "Languages", type: :request do
end
it "updates a language" do
- patch "/languages/#{@language.id}", params: @params
- expect(response).to redirect_to(languages_path)
+ patch "/admin/languages/#{@language.id}", params: @params
+ expect(response).to redirect_to(admin_languages_path)
end
it "requires params to update a language" do
@params = { language: { name: nil, invalid: "oh no" } }
- patch "/languages/#{@language.id}", params: @params
+ patch "/admin/languages/#{@language.id}", params: @params
expect(response).to have_http_status(:unprocessable_entity)
end
@@ -99,7 +99,7 @@ RSpec.describe "Languages", type: :request do
it "deletes a language" do
language = FactoryBot.create(:language)
language2 = FactoryBot.create(:language)
- delete "/languages/#{language.id}"
+ delete "/admin/languages/#{language.id}"
expect(Language.all).to eq([language2])
end
end
diff --git a/spec/requests/root_spec.rb b/spec/requests/root_spec.rb
index 810a364..6963d48 100644
--- a/spec/requests/root_spec.rb
+++ b/spec/requests/root_spec.rb
@@ -30,7 +30,7 @@ RSpec.describe "Root path", type: :request do
it "should have the 'Languages' link" do
sign_in FactoryBot.create(:user)
get root_path
- expect(response.body).to have_selector(%(a[href="#{languages_path}"]))
+ expect(response.body).to have_selector(%(a[href="#{admin_languages_path}"]))
end
it "should welcome user by username" do