Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Users can now upload 3 files at a time

  • Loading branch information...
commit cd8b466e2ee86733e9b26c6c9015d4b811d88169 1 parent fc09a26
Ryan Bigg authored May 07, 2011
1  .gitignore
@@ -2,3 +2,4 @@
2 2
 db/*.sqlite3
3 3
 log/*.log
4 4
 tmp/
  5
+public/system
1  app/controllers/tickets_controller.rb
@@ -11,6 +11,7 @@ class TicketsController < ApplicationController
11 11
   
12 12
   def new
13 13
     @ticket = @project.tickets.build
  14
+    3.times { @ticket.assets.build }
14 15
   end
15 16
   
16 17
   def create
3  app/models/asset.rb
... ...
@@ -0,0 +1,3 @@
  1
+class Asset < ActiveRecord::Base
  2
+  has_attached_file :asset
  3
+end
5  app/models/ticket.rb
... ...
@@ -1,8 +1,9 @@
1 1
 class Ticket < ActiveRecord::Base
2 2
   belongs_to :project
3 3
   belongs_to :user
4  
-
5  
-  has_attached_file :asset
  4
+  
  5
+  has_many :assets
  6
+  accepts_nested_attributes_for :assets
6 7
   
7 8
   validates :title, :presence => true
8 9
   validates :description, :presence => true, :length => { :minimum => 10 }
11  app/views/tickets/_form.html.erb
@@ -8,9 +8,12 @@
8 8
     <%= f.label :description %><br>
9 9
     <%= f.text_area :description %>
10 10
   </p>
11  
-  <p>
12  
-    <%= f.label :asset, "File" %>
13  
-    <%= f.file_field :asset %>
14  
-  </p>
  11
+  <% number = 0 %>
  12
+  <%= f.fields_for :assets do |asset| %>
  13
+    <p>
  14
+      <%= asset.label :asset, "File ##{number += 1}" %>
  15
+      <%= asset.file_field :asset %>
  16
+    </p>
  17
+  <% end %>
15 18
   <%= f.submit %>
16 19
 <% end %>
22  app/views/tickets/show.html.erb
@@ -15,17 +15,17 @@
15 15
   <small>Created by <%= @ticket.user.email %></small>
16 16
   <%= simple_format(@ticket.description) %>
17 17
 
18  
-  <% if @ticket.asset.exists? %>
19  
-    <h3>Attached File</h3>
20  
-    <div class="asset">
21  
-      <p>
22  
-        <%= link_to File.basename(@ticket.asset.path), 
23  
-        @ticket.asset.url %>
24  
-      </p>
25  
-      <p>
26  
-        <small><%= number_to_human_size(@ticket.asset.size) %>
27  
-       (<%= @ticket.asset.content_type %>)</small>
28  
-      </p>
  18
+  <% if @ticket.assets.exists? %>
  19
+    <h3>Attached Files</h3>
  20
+    <div class="assets">
  21
+      <% @ticket.assets.each do |asset| %>
  22
+        <p>
  23
+          <%= link_to File.basename(asset.asset_file_name), asset.asset.url %>
  24
+        </p>
  25
+        <p>
  26
+          <small><%= number_to_human_size(asset.asset.size) %></small>
  27
+        </p>
  28
+      <% end %>
29 29
     </div>
30 30
   <% end %>
31 31
 </div>
24  db/migrate/20110507074451_create_assets.rb
... ...
@@ -0,0 +1,24 @@
  1
+class CreateAssets < ActiveRecord::Migration
  2
+  def up
  3
+    create_table :assets do |t|
  4
+      t.string :asset_file_name
  5
+      t.integer :asset_file_size
  6
+      t.string :asset_content_type
  7
+      t.datetime :asset_updated_at
  8
+      t.integer :ticket_id
  9
+
  10
+      t.timestamps
  11
+    end
  12
+
  13
+    [:asset_file_name, 
  14
+     :asset_file_size,
  15
+     :asset_content_type,
  16
+     :asset_updated_at].each do |column|
  17
+      remove_column :tickets, column
  18
+    end
  19
+  end
  20
+
  21
+  def down
  22
+    drop_table :assets
  23
+  end
  24
+end
16  db/schema.rb
@@ -10,7 +10,17 @@
10 10
 #
11 11
 # It's strongly recommended to check this file into your version control system.
12 12
 
13  
-ActiveRecord::Schema.define(:version => 20110507060655) do
  13
+ActiveRecord::Schema.define(:version => 20110507074451) do
  14
+
  15
+  create_table "assets", :force => true do |t|
  16
+    t.string   "asset_file_name"
  17
+    t.integer  "asset_file_size"
  18
+    t.string   "asset_content_type"
  19
+    t.datetime "asset_updated_at"
  20
+    t.integer  "ticket_id"
  21
+    t.datetime "created_at"
  22
+    t.datetime "updated_at"
  23
+  end
14 24
 
15 25
   create_table "permissions", :force => true do |t|
16 26
     t.integer  "user_id"
@@ -34,10 +44,6 @@
34 44
     t.datetime "created_at"
35 45
     t.datetime "updated_at"
36 46
     t.integer  "user_id"
37  
-    t.string   "asset_file_name"
38  
-    t.string   "asset_content_type"
39  
-    t.integer  "asset_file_size"
40  
-    t.datetime "asset_updated_at"
41 47
   end
42 48
 
43 49
   add_index "tickets", ["project_id"], :name => "index_tickets_on_project_id"
12  features/creating_tickets.feature
@@ -37,9 +37,13 @@ Feature: Creating Tickets
37 37
     
38 38
   Scenario: Creating a ticket with an attachment
39 39
     When I fill in "Title" with "Add documentation for blink tag"
40  
-    And I fill in "Description" with "The blink tag has an unknown speed attribute"
41  
-    And I attach the file "spec/fixtures/card.jpg" to "File"
  40
+    And I fill in "Description" with "The blink tag has an undocumented speed attribute"
  41
+    And I attach the file "spec/fixtures/speed.txt" to "File #1"
  42
+    Then show me the page
  43
+    And I attach the file "spec/fixtures/spin.txt" to "File #2"
  44
+    And I attach the file "spec/fixtures/gradient.txt" to "File #3"
42 45
     And I press "Create Ticket"
43 46
     Then I should see "Ticket has been created."
44  
-    Then show me the page
45  
-    Then I should see "speed.txt" within "#ticket .asset"
  47
+    And I should see "speed.txt" within "#ticket .assets"
  48
+    And I should see "spin.txt" within "#ticket .assets"
  49
+    And I should see "gradient.txt" within "#ticket .assets"
1  spec/fixtures/gradient.txt
... ...
@@ -0,0 +1 @@
  1
+Everything looks better with a gradient!
1  spec/fixtures/spin.txt
... ...
@@ -0,0 +1 @@
  1
+Spinning blink tags have a 200% higher click rate!
5  spec/models/asset_spec.rb
... ...
@@ -0,0 +1,5 @@
  1
+require 'spec_helper'
  2
+
  3
+describe Asset do
  4
+  pending "add some examples to (or delete) #{__FILE__}"
  5
+end

0 notes on commit cd8b466

Please sign in to comment.
Something went wrong with that request. Please try again.