diff options
| -rw-r--r-- | help/app/controllers/tickets_controller.rb | 10 | ||||
| -rw-r--r-- | help/app/models/ticket.rb | 11 | ||||
| -rw-r--r-- | help/app/views/tickets/new.html.haml | 9 | 
3 files changed, 15 insertions, 15 deletions
| diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index 2e681b2..be07309 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -4,13 +4,14 @@ class TicketsController < ApplicationController    def new      @ticket = Ticket.new +    @ticket.comments.build    end    def create      @ticket = Ticket.new #:created_by => User.current_test.id      @ticket.attributes = params[:ticket]#.except(:comments)      @ticket.created_by = User.current_test.id if User.current_test -    add_comment +    #instead of calling add_comment, we are using comment_attributes= from the Ticket model      if @ticket.save        respond_with(@ticket) @@ -22,13 +23,14 @@ class TicketsController < ApplicationController    def show      @ticket = Ticket.find(params[:id]) +    # build ticket comments?    end    def update      @ticket = Ticket.find(params[:id]) -    add_comment +    add_comment #or should we use ticket attributes?      @ticket.save -    redirect_to @ticket +    redirect_to @ticket #difft behavior on failure?    end    def index @@ -38,6 +40,8 @@ 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    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 8cec0df..e829a5f 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -29,8 +29,6 @@ class Ticket < CouchRest::Model::Base    timestamps! -  #accepts_nested_attributes_for :ticketcomments #?? -      #before_validation :set_created_by, :set_code, :set_email, :on => :create    before_validation :set_code, :set_email, :on => :create @@ -75,9 +73,12 @@ class Ticket < CouchRest::Model::Base      save    end -  #probably not useful, but trying it: -  def ticket_comment_attributes=(attributes) -    @ticket_comment =  TicketComment.new(attributes) +  def comments_attributes=(attributes) +    comment = TicketComment.new(attributes.values.first) #TicketComment.new(attributes) +    comment.posted_by = User.current_test.id if User.current_test +    comment.posted_at = Time.now +    comments << comment +        end  =begin diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml index d0e6939..0a6b25b 100644 --- a/help/app/views/tickets/new.html.haml +++ b/help/app/views/tickets/new.html.haml @@ -1,18 +1,13 @@  %h2=t :new_ticket  = simple_form_for (@ticket, :html => {:novalidate => true})  do |f| #turn off html5 validations to test -  = @ticket.errors.messages +  = #@ticket.errors.messages    = f.input :title    = #f.input :email #if there is no current_user    = f.input :email if !User.current_test #hmm--might authenticated users want to submit an alternate email? -  = #f.simple_fields_for :comment do |c| -  = #c.input :body, :label => 'Comment', :as => :text -  = #f.input :comments, :label => 'Comment', :as => :text -  = f.fields_for :comment do |c| +  = f.simple_fields_for :comments do |c|      = c.input :body, :label => 'Comment', :as => :text - -  = #f.input :comment    = #render :partial => 'new_comment' #what we were using    = # regarding_user if not logged in    = # email if not logged in | 
