Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Users can now upload 3 files at a time

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