diff options
author | jessib <jessib@riseup.net> | 2012-10-12 14:42:57 -0700 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2012-10-12 14:42:57 -0700 |
commit | 56273c13f54a872d02db286c90a8d5103cf7a663 (patch) | |
tree | 2a093d43f09a3179d571f6f7d887a1176e5c27f7 /help | |
parent | 336d5f786bbd1aaf1847007db64e55f96e585b9d (diff) |
more work on ticket creation/updating functionality
Diffstat (limited to 'help')
-rw-r--r-- | help/app/controllers/tickets_controller.rb | 34 | ||||
-rw-r--r-- | help/app/models/ticket.rb | 2 | ||||
-rw-r--r-- | help/app/views/tickets/_comment.html.haml | 3 | ||||
-rw-r--r-- | help/app/views/tickets/_new_comment.html.haml | 1 | ||||
-rw-r--r-- | help/app/views/tickets/new.html.haml | 2 | ||||
-rw-r--r-- | help/app/views/tickets/show.html.haml | 10 |
6 files changed, 37 insertions, 15 deletions
diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index be07309..f4b38de 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -13,24 +13,39 @@ class TicketsController < ApplicationController @ticket.created_by = User.current_test.id if User.current_test #instead of calling add_comment, we are using comment_attributes= from the Ticket model - if @ticket.save - respond_with(@ticket) - else - respond_with(@ticket, :location => new_ticket_path ) - end + flash[:notice] = 'Ticket was successfully created.' if @ticket.save + respond_with(@ticket) end +=begin + def edit + @ticket = Ticket.find(params[:id]) + @ticket.comments.build + # build ticket comments? + end +=end + def show @ticket = Ticket.find(params[:id]) + # @ticket.comments.build # build ticket comments? end def update @ticket = Ticket.find(params[:id]) - add_comment #or should we use ticket attributes? - @ticket.save - redirect_to @ticket #difft behavior on failure? + @ticket.attributes = params[:ticket] + #add_comment #or should we use ticket attributes? + # @ticket.save + if @ticket.save + flash[:notice] = 'Ticket was successfully updated.' + respond_with @ticket + else + #redirect_to [:show, @ticket] # + flash[:alert] = 'Ticket has not been changed' + redirect_to @ticket + #respond_with(@ticket) # why does this go to edit?? redirect??? + end end def index @@ -40,8 +55,7 @@ class TicketsController < ApplicationController private - # not using now when creating tickets, we are using comment_attributes= from the Ticket model - #not yet sure about updating tickets + # not using now, as we are using comment_attributes= from the Ticket model def add_comment comment = TicketComment.new(params[:comment]) comment.posted_by = User.current_test.id if User.current_test #could be nil diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index e829a5f..537a7c6 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -37,7 +37,7 @@ class Ticket < CouchRest::Model::Base end validates :title, :presence => true - validates :comments, :presence => true #do we want it like this? + #validates :comments, :presence => true #do we want it like this? # html5 has built-in validation which isn't ideal, as it says 'please enter an email address' for invalid email addresses, which implies an email address is required, and it is not. diff --git a/help/app/views/tickets/_comment.html.haml b/help/app/views/tickets/_comment.html.haml index 77e29b8..19e1ddf 100644 --- a/help/app/views/tickets/_comment.html.haml +++ b/help/app/views/tickets/_comment.html.haml @@ -1,4 +1,5 @@ -%div +- # style is super ugly but just for now +%div{:style => "border: solid 1px"} - if User.find(comment.posted_by) Posted by = User.find(comment.posted_by).login diff --git a/help/app/views/tickets/_new_comment.html.haml b/help/app/views/tickets/_new_comment.html.haml index bf88da6..a924dfd 100644 --- a/help/app/views/tickets/_new_comment.html.haml +++ b/help/app/views/tickets/_new_comment.html.haml @@ -1,2 +1,3 @@ += #do we want this partial? not using it now = simple_fields_for :comment do |c| = c.input :body, :label => 'Comment', :as => :text diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml index 0a6b25b..d784720 100644 --- a/help/app/views/tickets/new.html.haml +++ b/help/app/views/tickets/new.html.haml @@ -13,4 +13,4 @@ = # email if not logged in = #f.button :submit, :value => t(:submit), :class => 'btn-primary' = f.button :submit - = link_to t(:cancel), root_url, :class => :btn + = link_to t(:cancel), tickets_path, :class => :btn diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml index 1e1fab3..04dd676 100644 --- a/help/app/views/tickets/show.html.haml +++ b/help/app/views/tickets/show.html.haml @@ -1,3 +1,7 @@ +- if flash[:notice] + =flash[:notice] +- if flash[:alert] + =flash[:alert] %h2= @ticket.title is open? = @ticket.is_open @@ -6,6 +10,8 @@ code: = render(:partial => "comment", :collection => @ticket.comments) = simple_form_for (@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test - = render :partial => 'new_comment' + = f.simple_fields_for :comments, TicketComment.new do |c| + = c.input :body, :label => 'Comment', :as => :text + = #render :partial => 'new_comment' = f.button :submit - = link_to t(:cancel), root_url, :class => :btn
\ No newline at end of file + = link_to t(:cancel), tickets_path, :class => :btn
\ No newline at end of file |