From cf9ed38ab1840092352efdbb71bfeb5bc3b9f9d5 Mon Sep 17 00:00:00 2001 From: jessib Date: Wed, 10 Oct 2012 15:52:08 -0700 Subject: Some tweaks to get server-side validation working when adding the embedded ticket comment to a new ticket. --- help/app/controllers/tickets_controller.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'help/app/controllers') 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 -- cgit v1.2.3