Skip to content
Browse files

Users can tag tikcets upon creation

  • Loading branch information...
1 parent 8be8c13 commit 4f656da241ea0a43638722cbea929223a4115dc3 @Lin4ipsum committed
View
1 app/controllers/tickets_controller.rb
@@ -17,6 +17,7 @@ def new
def create
@ticket = @project.tickets.build(params[:ticket].merge!(:user => current_user))
if @ticket.save
+ @ticket.tag!(params[:tags])
flash[:notice] = "Ticket has been created."
redirect_to [@project, @ticket]
else
View
2 app/models/tag.rb
@@ -0,0 +1,2 @@
+class Tag < ActiveRecord::Base
+end
View
10 app/models/ticket.rb
@@ -5,9 +5,19 @@ class Ticket < ActiveRecord::Base
has_many :assets
accepts_nested_attributes_for :assets
has_many :comments
+ has_and_belongs_to_many :tags
validates :title, :presence => true
validates :description, presence: true,
length: { minimum: 10 }
+
+ def tag!(tags)
+ tags = tags.split(" ").map do |tag|
+ Tag.find_or_create_by_name(tag)
+ end
+
+ self.tags << tags
+ end
+
end
View
1 app/views/tags/_tag.html.erb
@@ -0,0 +1 @@
+<span class='tag'><%= tag.name %></span>
View
5 app/views/tickets/_form.html.erb
@@ -9,6 +9,11 @@
<%= f.label :description %>
<%= f.text_area :description %>
</p>
+
+ <p>
+ <%= label_tag :tags %>
+ <%= text_field_tag :tags, params[:tags] %>
+ </p>
<% number = 0 %>
<div id="files">
View
27 app/views/tickets/show.html.erb
@@ -1,20 +1,21 @@
<div id='ticket'>
- <h2><%= @ticket.title %></h2>
- <br><small>Created by <%= @ticket.user.email %></small>
- <%= render @ticket.state if @ticket.state %>
- <%= simple_format(@ticket.description) %>
+ <h2><%= @ticket.title %></h2>
+ <br><small>Created by <%= @ticket.user.email %></small>
+ <%= render @ticket.state if @ticket.state %>
+ <%= simple_format(@ticket.description) %>
+ <div id='tags'><%= render @ticket.tags %></div>
<% if @ticket.assets.exists? %>
- <h3>Attached Files</h3>
+ <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 %>
+ <% @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 %>
View
2,656 chromedriver.log
1,335 additions, 1,321 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
12 db/migrate/20120522184816_create_tags.rb
@@ -0,0 +1,12 @@
+class CreateTags < ActiveRecord::Migration
+ def change
+ create_table :tags do |t|
+ t.string :name
+ end
+ end
+
+ create_table :tags_tickets, :id => false do |t|
+ t.integer :tag_id, :ticket_id
+ end
+
+end
View
11 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120518213238) do
+ActiveRecord::Schema.define(:version => 20120522184816) do
create_table "assets", :force => true do |t|
t.string "asset_file_name"
@@ -57,6 +57,15 @@
t.boolean "default"
end
+ create_table "tags", :force => true do |t|
+ t.string "name"
+ end
+
+ create_table "tags_tickets", :id => false, :force => true do |t|
+ t.integer "tag_id"
+ t.integer "ticket_id"
+ end
+
create_table "tickets", :force => true do |t|
t.string "title"
t.text "description"
View
11 features/creating_tickets.feature
@@ -65,6 +65,11 @@ Scenario: Creating a ticket with an attachment
And I should see "spin.txt" within "#ticket .assets"
When I follow "speed.txt"
-
-
-
+Scenario: Creating a ticket with tags
+ When I fill in "Title" with "Non-standards compliance"
+ And I fill in "Description" with "My pages are ugly!"
+ And I fill in "Tags" with "browser visual"
+ And I press "Create Ticket"
+ Then I should see "Ticket has been created."
+ And I should see "browser" within "#ticket #tags"
+ And I should see "visual" within "#ticket #tags"
View
5 spec/models/tag_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Tag do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 4f656da

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