Kind of fixed version:

def create
  if params[:ticket][:title].empty?
    flash[:notice] = 'Please fill fields marked with *'
    redirect_to :action => 'create_ticket_ui'
  else
  @contact_id =
ContactEmailAddress.get_contact_id(params[:contact_email][:email])
  begin
    ActiveRecord::Base.transaction do
      ServiceDesk.create_ticket(@contact_id,params[:ticket]) #Now create a
new sd ticket
    end
  rescue
  end
end

The reason why your editor says it's wrong is a superfluous end before the
rescue clause.

There are a couple of other things you want to change here as well, but that
depends on your implementation.

   - Use ActiveRecord validations to tell the user which field the error was
   on. This also means you can be very specific about what can go into each
   field.
   - Redirect on successful creation of ticket, not on failure (that way the
   fields can remain filled out)

Here is a version somewhat easier to work with. I don't know how
ServiceDesk.create_ticket works, so I modified it to new_ticket (which
doesn't actually save the ticket that has been created, just returns it).

def create
  if request.post?
    @contact_id =
ContactEmailAddress.get_contact_id(params[:contact_email][:email])
    @ticket     = ServiceDesk.new_ticket(@contact_id, params[:ticket])

    if @ticket.save
      redirect_to :action => 'create_ticket_ui'
      return
    end
  end

  @ticket ||= ServiceDesk.new_ticket
end

Hope this helps.


Cheers,
Morgan Grubb.



2008/11/4 Sijo Kg <[EMAIL PROTECTED]>

>
> I have an action like
>
> def create
>    if params[:ticket][:title].empty?
>      flash[:notice] = 'Please fill fields marked with *'
>      redirect_to :action => 'create_ticket_ui'
>    else
>  @contact_id =
> ContactEmailAddress.get_contact_id(params[:contact_email][:email])
>      begin
>        ActiveRecord::Base.transaction do
>        #Now create a new sd ticket
>         ServiceDesk.create_ticket(@contact_id,params[:ticket])
>        end #transaction end
>      end #begin end
>       rescue   #here is the problem
>    end #outer if else end
>  end
>
>     My problem is when I start typing rescue as above IDE shows Syntax
> error.Could you please help me to solve this? What I tried is to get the
> error in transaction rescued Already inside the model also I have placed
> the code in transaction begin end block and re raised any exception from
> there
>
> Thanks in advance
> Sijo
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>


-- 
--------------------------------------------------------------------------
Morgan Grubb - Just Landed
General Tel: +34 91 590 2611
[EMAIL PROTECTED]
--------------------------------------------------------------------------
http://www.justlanded.com - Helping people abroad!
30 countries, in up to 8 languages, more to come...
--------------------------------------------------------------------------

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to