add attachment model and add paperclip

This commit is contained in:
Reinier Balt 2014-07-03 23:21:39 +02:00
parent 013b260a1b
commit 76de5bf2b3
8 changed files with 78 additions and 22 deletions

View file

@ -32,6 +32,8 @@ gem "htmlentities"
gem "swf_fu"
gem "rails_autolink"
gem 'thin'
gem "cache_digests"
gem "paperclip"
# To use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'

View file

@ -114,6 +114,12 @@ GEM
nokogiri
rack (1.5.5)
rack-dev-mark (0.7.3)
paperclip (4.1.1)
activemodel (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (~> 0.5.3)
mime-types
polyglot (0.3.5)
rack (>= 1.1)
rack-mini-profiler (0.9.2)
rack (>= 1.1.3)
@ -228,6 +234,7 @@ DEPENDENCIES
jquery-rails
mocha
mysql2
paperclip
rack-dev-mark
rack-mini-profiler
rails (~> 4.1.11)

10
app/models/attachment.rb Normal file
View file

@ -0,0 +1,10 @@
class Attachment < ActiveRecord::Base
belongs_to :todo, touch: true
has_attached_file :file,
url: '/:class/:id/:basename.:extension',
path: ":rails_root/db/assets/#{Rails.env}/:class/:id/:basename.:extension"
do_not_validate_attachment_file_type :file
# validates_attachment_content_type :file, :content_type => ["text/plain"]
end

View file

@ -25,6 +25,8 @@ class Todo < ActiveRecord::Base
has_many :pending_successors, -> {where('todos.state = ?', 'pending')}, :through => :predecessor_dependencies,
:source => :successor
has_many :attachments, dependent: :delete_all
# scopes for states of this todo
scope :active, -> { where state: 'active' }
scope :active_or_hidden, -> { where "todos.state = ? OR todos.state = ?", 'active', 'project_hidden' }

View file

@ -0,0 +1,9 @@
class CreateAttachments < ActiveRecord::Migration
def change
create_table :attachments do |t|
t.references :todo, index: true
t.attachment :file
t.timestamps
end
end
end

View file

@ -11,11 +11,23 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150209233951) do
ActiveRecord::Schema.define(version: 20140703191545) do
create_table "attachments", force: true do |t|
t.integer "todo_id"
t.string "file_file_name"
t.string "file_content_type"
t.integer "file_file_size"
t.datetime "file_updated_at"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "attachments", ["todo_id"], name: "index_attachments_on_todo_id", using: :btree
create_table "contexts", force: true do |t|
t.string "name", null: false
t.integer "position"
t.integer "position", default: 0
t.integer "user_id", default: 1
t.datetime "created_at"
t.datetime "updated_at"
@ -85,11 +97,11 @@ ActiveRecord::Schema.define(version: 20150209233951) do
add_index "preferences", ["user_id"], name: "index_preferences_on_user_id", using: :btree
create_table "projects", force: true do |t|
t.string "name", null: false
t.integer "position"
t.integer "user_id", default: 1
t.text "description"
t.string "state", limit: 20, null: false
t.string "name", null: false
t.integer "position", default: 0
t.integer "user_id", default: 1
t.text "description", limit: 16777215
t.string "state", limit: 20, null: false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "default_context_id"
@ -104,17 +116,17 @@ ActiveRecord::Schema.define(version: 20150209233951) do
add_index "projects", ["user_id"], name: "index_projects_on_user_id", using: :btree
create_table "recurring_todos", force: true do |t|
t.integer "user_id", default: 1
t.integer "context_id", null: false
t.integer "user_id", default: 1
t.integer "context_id", null: false
t.integer "project_id"
t.string "description", null: false
t.text "notes"
t.string "state", limit: 20, null: false
t.string "description", null: false
t.text "notes", limit: 16777215
t.string "state", limit: 20, null: false
t.datetime "start_from"
t.string "ends_on"
t.datetime "end_date"
t.integer "number_of_occurrences"
t.integer "occurrences_count", default: 0
t.integer "number_of_occurences"
t.integer "occurences_count", default: 0
t.string "target"
t.integer "show_from_delta"
t.string "recurring_period"
@ -141,7 +153,7 @@ ActiveRecord::Schema.define(version: 20150209233951) do
t.datetime "updated_at"
end
add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
add_index "sessions", ["session_id"], name: "sessions_session_id_index", using: :btree
create_table "taggings", force: true do |t|
t.integer "taggable_id"
@ -162,19 +174,19 @@ ActiveRecord::Schema.define(version: 20150209233951) do
add_index "tags", ["name"], name: "index_tags_on_name", using: :btree
create_table "todos", force: true do |t|
t.integer "context_id", null: false
t.integer "context_id", null: false
t.integer "project_id"
t.string "description", null: false
t.text "notes"
t.string "description", null: false
t.text "notes", limit: 16777215
t.datetime "created_at"
t.datetime "due"
t.datetime "completed_at"
t.integer "user_id", default: 1
t.integer "user_id", default: 1
t.datetime "show_from"
t.string "state", limit: 20, null: false
t.string "state", limit: 20, null: false
t.integer "recurring_todo_id"
t.datetime "updated_at"
t.text "rendered_notes"
t.text "rendered_notes", limit: 16777215
end
add_index "todos", ["context_id"], name: "index_todos_on_context_id", using: :btree
@ -212,7 +224,7 @@ ActiveRecord::Schema.define(version: 20150209233951) do
create_table "users", force: true do |t|
t.string "login", limit: 80, null: false
t.string "crypted_password", limit: 60, null: false
t.string "crypted_password", limit: 60
t.string "token"
t.boolean "is_admin", default: false, null: false
t.string "first_name"

7
test/fixtures/attachments.yml vendored Normal file
View file

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

View file

@ -0,0 +1,7 @@
require 'test_helper'
class AttachmentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end