diff --git a/app/assets/javascripts/welcome.coffee b/app/assets/javascripts/welcome.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/welcome.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000..5cda0a8 --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,24 @@ +class CategoriesController < ApplicationController + + def index + end + + def show + end + + def new + end + + def edit + end + + def create + end + + def update + end + + def destroy + end + +end diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index fd75646..62dc0a9 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -5,7 +5,8 @@ class DocumentsController < ApplicationController # GET /documents.json def index @documents = Document.where(user_id: current_user) - @categories = Category.where(user_id: current_user) + @user = current_user + @categories = @user.categories.all end # GET /documents/1 @@ -26,6 +27,8 @@ def edit # POST /documents.json def create @document = current_user.documents.build(document_params) + @user = current_user + @categories = @user.categories.all respond_to do |format| if @document.save @@ -41,6 +44,9 @@ def create # PATCH/PUT /documents/1 # PATCH/PUT /documents/1.json def update + @user = current_user + @categories = @user.categories.all + respond_to do |format| if @document.update(document_params) format.html { render :edit } diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 0000000..e06f315 --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/models/category.rb b/app/models/category.rb index 54cb6ae..5c966e8 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,2 +1,5 @@ class Category < ApplicationRecord + + has_many :documents + end diff --git a/app/models/user.rb b/app/models/user.rb index 96cde6d..b0d6446 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,5 +5,7 @@ class User < ApplicationRecord :recoverable, :rememberable, :trackable, :validatable has_many :documents + + has_many :categories, through: :documents end diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb new file mode 100644 index 0000000..5e91def --- /dev/null +++ b/app/views/categories/show.html.erb @@ -0,0 +1,5 @@ +

+ Category: +

+ +<%= link_to 'Back', root_path %> \ No newline at end of file diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index 0358c16..b1e30b7 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -12,55 +12,34 @@ diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index 24ab8be..211c905 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -1,5 +1,3 @@ -

<%= notice %>

-

Title: <%= @document.title %> diff --git a/config/routes.rb b/config/routes.rb index aa0c6c3..28acc44 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ get 'welcome/index' resources :documents + resources :categories authenticated :user do root to: "documents#index", as: "authenticated_root" diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000..0a3c392 --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CategoriesControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end