浏览代码

Some more functions.

master
父节点
当前提交
493973bdd3
共有 11 个文件被更改,包括 66 次插入3 次删除
  1. +2
    -1
      app/controllers/documents_controller.rb
  2. +1
    -0
      app/controllers/sessions_controller.rb
  3. +9
    -1
      app/models/document.rb
  4. +3
    -0
      app/models/tag.rb
  5. +2
    -0
      app/models/user.rb
  6. +10
    -0
      db/migrate/20161124165646_create_tags.rb
  7. +5
    -0
      db/migrate/20161124171050_add_user_to_document.rb
  8. +5
    -0
      db/migrate/20161124174721_create_join_table_documents_tags.rb
  9. +15
    -1
      db/schema.rb
  10. +7
    -0
      test/fixtures/tags.yml
  11. +7
    -0
      test/models/tag_test.rb

+ 2
- 1
app/controllers/documents_controller.rb 查看文件

@@ -4,7 +4,7 @@ class DocumentsController < ApplicationController
# GET /documents
# GET /documents.json
def index
@documents = Document.all
@documents = User.find(session[:user_id]).documents
end

# GET /documents/1
@@ -27,6 +27,7 @@ class DocumentsController < ApplicationController
@document = Document.new(document_params)

@document.name = @document.doc_file_name
@document.user = User.find(session[:user_id])

if Document.exists?(doc_fingerprint: @document.doc_fingerprint)
end


+ 1
- 0
app/controllers/sessions_controller.rb 查看文件

@@ -16,5 +16,6 @@ class SessionsController < ApplicationController

def destroy
session[:user_id] = nil
redirect_to documents_url
end
end

+ 9
- 1
app/models/document.rb 查看文件

@@ -1,4 +1,12 @@
class Document < ApplicationRecord
has_attached_file :doc, adapter_options: { hash_digest: Digest::SHA256 }
belongs_to :user
has_and_belongs_to_many :tags

has_attached_file :doc,
{
adapter_options: { hash_digest: Digest::SHA256 },
url: "/system/:class/:attachment/:id_partition/:style/:hash.:extension",
hash_secret: Rails.application.secrets.secret_key_base
}
validates_attachment_content_type :doc, content_type: 'application/pdf'
end

+ 3
- 0
app/models/tag.rb 查看文件

@@ -0,0 +1,3 @@
class Tag < ApplicationRecord
has_and_belongs_to_many :documents
end

+ 2
- 0
app/models/user.rb 查看文件

@@ -1,3 +1,5 @@
class User < ApplicationRecord
has_secure_password

has_many :documents, dependent: :destroy
end

+ 10
- 0
db/migrate/20161124165646_create_tags.rb 查看文件

@@ -0,0 +1,10 @@
class CreateTags < ActiveRecord::Migration[5.0]
def change
create_table :tags do |t|
t.string :value
t.boolean :automatically_asigned

t.timestamps
end
end
end

+ 5
- 0
db/migrate/20161124171050_add_user_to_document.rb 查看文件

@@ -0,0 +1,5 @@
class AddUserToDocument < ActiveRecord::Migration[5.0]
def change
add_reference :documents, :user, index: true
end
end

+ 5
- 0
db/migrate/20161124174721_create_join_table_documents_tags.rb 查看文件

@@ -0,0 +1,5 @@
class CreateJoinTableDocumentsTags < ActiveRecord::Migration[5.0]
def change
create_join_table :documents, :tags
end
end

+ 15
- 1
db/schema.rb 查看文件

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20161124142626) do
ActiveRecord::Schema.define(version: 20161124174721) do

create_table "documents", force: :cascade do |t|
t.string "name"
@@ -21,7 +21,21 @@ ActiveRecord::Schema.define(version: 20161124142626) do
t.integer "doc_file_size"
t.datetime "doc_updated_at"
t.string "doc_fingerprint"
t.integer "user_id"
t.index ["doc_fingerprint"], name: "index_documents_on_doc_fingerprint"
t.index ["user_id"], name: "index_documents_on_user_id"
end

create_table "documents_tags", id: false, force: :cascade do |t|
t.integer "document_id", null: false
t.integer "tag_id", null: false
end

create_table "tags", force: :cascade do |t|
t.string "value"
t.boolean "automatically_asigned"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "users", force: :cascade do |t|


+ 7
- 0
test/fixtures/tags.yml 查看文件

@@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
value: MyString

two:
value: MyString

+ 7
- 0
test/models/tag_test.rb 查看文件

@@ -0,0 +1,7 @@
require 'test_helper'

class TagTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

正在加载...
取消
保存