Skip to content

Commit 122545d

Browse files
committed
removed form upload for dummy app form page, introduced active storage to dummy app
1 parent dc0b197 commit 122545d

File tree

6 files changed

+56
-19
lines changed

6 files changed

+56
-19
lines changed

spec/dummy/app/controllers/my_app_controller.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ def some_action
3939
end
4040

4141
def form_action
42-
p 'Controller action'
43-
p dummy_model_params[:file]
44-
p dummy_model_params[:files]
45-
dummy_model_params[:files]&.each { |file| p file }
4642
@dummy_model = DummyModel.create(dummy_model_params)
4743
if @dummy_model.errors.any?
4844
render json: {
@@ -88,9 +84,7 @@ def delete_dummy_model
8884
def dummy_model_params
8985
params.require(:dummy_model).permit(
9086
:title,
91-
:description,
92-
:file,
93-
files: []
87+
:description
9488
)
9589
end
9690

spec/dummy/app/matestack/pages/my_app/my_fourth_page.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ def response
1313
form my_form_config, :include do
1414
form_input key: :title, type: :text, placeholder: "title"
1515
br
16-
form_input key: :file, type: :file
17-
br
18-
form_input key: :files, type: :file, multiple: true
19-
br
2016
form_submit do
2117
button text: "Submit me!"
2218
end
@@ -48,9 +44,6 @@ def my_form_config
4844
for: @dummy_model,
4945
method: :post,
5046
path: :form_action_path,
51-
attributes: {
52-
enctype: 'multipart/form-data'
53-
},
5447
success: {
5548
emit: "form_succeeded"
5649
},

spec/dummy/app/models/dummy_model.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
class DummyModel < ApplicationRecord
22

33
validates :title, presence: true, uniqueness: true
4-
5-
attr_accessor :file
6-
attr_accessor :files
7-
4+
5+
has_one_attached :file
6+
has_many_attached :files
87
end

spec/dummy/app/models/test_model.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
class TestModel < ApplicationRecord
2+
3+
has_one_attached :file
4+
25
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This migration comes from active_storage (originally 20170806125915)
2+
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
3+
def change
4+
create_table :active_storage_blobs do |t|
5+
t.string :key, null: false
6+
t.string :filename, null: false
7+
t.string :content_type
8+
t.text :metadata
9+
t.bigint :byte_size, null: false
10+
t.string :checksum, null: false
11+
t.datetime :created_at, null: false
12+
13+
t.index [ :key ], unique: true
14+
end
15+
16+
create_table :active_storage_attachments do |t|
17+
t.string :name, null: false
18+
t.references :record, null: false, polymorphic: true, index: false
19+
t.references :blob, null: false
20+
21+
t.datetime :created_at, null: false
22+
23+
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
24+
t.foreign_key :active_storage_blobs, column: :blob_id
25+
end
26+
end
27+
end

spec/dummy/db/schema.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,28 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2019_09_08_153924) do
13+
ActiveRecord::Schema.define(version: 2020_04_27_170812) do
14+
15+
create_table "active_storage_attachments", force: :cascade do |t|
16+
t.string "name", null: false
17+
t.string "record_type", null: false
18+
t.integer "record_id", null: false
19+
t.integer "blob_id", null: false
20+
t.datetime "created_at", null: false
21+
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
22+
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
23+
end
24+
25+
create_table "active_storage_blobs", force: :cascade do |t|
26+
t.string "key", null: false
27+
t.string "filename", null: false
28+
t.string "content_type"
29+
t.text "metadata"
30+
t.bigint "byte_size", null: false
31+
t.string "checksum", null: false
32+
t.datetime "created_at", null: false
33+
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
34+
end
1435

1536
create_table "dummy_child_models", force: :cascade do |t|
1637
t.string "title"

0 commit comments

Comments
 (0)