Skip to content

Commit

Permalink
Users can now leave comments on tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin4ipsum committed May 9, 2012
1 parent a544fe6 commit 74f2808
Show file tree
Hide file tree
Showing 21 changed files with 1,454 additions and 1,312 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -32,6 +32,7 @@ group :test do
gem 'database_cleaner'
gem 'factory_girl'
gem 'email_spec'
gem 'launchy'
end

gem 'devise', '~> 1.4.3'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -28,6 +28,7 @@ GEM
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.8)
archive-tar-minitar (0.5.2)
arel (3.0.2)
bcrypt-ruby (3.0.1)
Expand Down Expand Up @@ -88,6 +89,8 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
launchy (2.1.0)
addressable (~> 2.2.6)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
mail (2.4.4)
Expand Down Expand Up @@ -199,6 +202,7 @@ DEPENDENCIES
email_spec
factory_girl
jquery-rails
launchy
paperclip
rails (= 3.2.2)
rspec-rails (~> 2.5)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/comments.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/comments.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the comments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
20 changes: 20 additions & 0 deletions app/controllers/comments_controller.rb
@@ -0,0 +1,20 @@
class CommentsController < ApplicationController
before_filter :authenticate_user!
before_filter :find_ticket

def create
@comment = @ticket.comments.build(params[:comment].merge(:user => current_user))
if @comment.save
flash[:notice] = "Comment has been created."
redirect_to [@ticket.project, @ticket]
else
flash[:alert] = "Comment has not been created."
render :template => "tickets/show"
end
end

private
def find_ticket
@ticket = Ticket.find(params[:ticket_id])
end
end
1 change: 1 addition & 0 deletions app/controllers/tickets_controller.rb
Expand Up @@ -26,6 +26,7 @@ def create
end

def show
@comment = @ticket.comments.build
end

def edit
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/comments_helper.rb
@@ -0,0 +1,2 @@
module CommentsHelper
end
5 changes: 5 additions & 0 deletions app/models/comment.rb
@@ -0,0 +1,5 @@
class Comment < ActiveRecord::Base
belongs_to :user

validates :text, :presence => true
end
1 change: 1 addition & 0 deletions app/models/ticket.rb
Expand Up @@ -3,6 +3,7 @@ class Ticket < ActiveRecord::Base
belongs_to :user
has_many :assets
accepts_nested_attributes_for :assets
has_many :comments

validates :title, :presence => true
validates :description, presence: true,
Expand Down
4 changes: 4 additions & 0 deletions app/views/comments/_comment.html.erb
@@ -0,0 +1,4 @@
<%= div_for(comment) do%>
<h4><%= comment.user %></h4>
<%= simple_format(comment.text)%>
<% end %>
10 changes: 10 additions & 0 deletions app/views/comments/_form.html.erb
@@ -0,0 +1,10 @@
<strong>New Comment</strong>
<%= form_for [@ticket, @comment] do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>

<%= f.submit %>
<% end %>
11 changes: 6 additions & 5 deletions app/views/projects/index.html.erb
Expand Up @@ -3,8 +3,9 @@
<% end %>

<h2> Projects</h2>
<ul>
<% @projects.each do|project| %>
<li><%= link_to project.name, project%></li>
<% end %>
</ul>

<ul id='projects'>
<% for project in @projects %>
<li><%= link_to project.name, project %></li>
<% end %>
</ul>
11 changes: 11 additions & 0 deletions app/views/tickets/show.html.erb
Expand Up @@ -28,3 +28,14 @@
:method => :delete,
:confirm => "Are you sure you want to delete this ticket?" %>
<% end %>

<h3>Comments</h3>
<div id='comments'>
<% if @ticket.comments.exists?%> <co id='ch10_191_1' />
<%= render @ticket.comments.select(&:persisted?) %>
<% else %>
There are no comments for this ticket.
<% end %>
</div>

<%= render "comments/form" %>

0 comments on commit 74f2808

Please sign in to comment.