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/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > 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 morgan.grubb-9pJevV/ekkYyY3YROqfsYA@public.gmane.org -------------------------------------------------------------------------- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Thanks for your reply. But I did not understand what you mean by superfluous end...But the problem solved when I use begin end for the whole action instead of else part only..So still dont know why Syntax error at first Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 4, 8:45 am, Sijo Kg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi > Thanks for your reply. But I did not understand what you mean by > superfluous end...But the problem solved when I use begin end for the > whole action instead of else part only..So still dont know why Syntax > error at first >because the correct syntax is begin ... rescue ... end (you could have multiple rescue clauses etc) not begin ... end rescue ... end Fred> Sijo > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Thanks for the reply Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi One more question related to this What I understood from your reply was rescue placed inside the begin end block(Am I right?)..Could you please tell how following working ? begin SDMailer.delive_to_send_mail_to_user(name,email_id,ticket_no) unless email_id.blank? end rescue Exception => e: puts e.to_s And the o/p is (here i gave delive deliberately instead of deliver) undefined method `delive_to_send_mail_to_online_user_on_ticket_creation'' for SDMailer:Class Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 4 Nov 2008, at 10:00, Sijo Kg wrote:> > Hi > One more question related to this What I understood from your reply > was rescue placed inside the begin end block(Am I right?)..Could you > please tell how following working ? > > begin > SDMailer.delive_to_send_mail_to_user(name,email_id,ticket_no) unless > email_id.blank? > end > rescue Exception => e: > puts e.to_s > > And the o/p is (here i gave delive deliberately instead of deliver) > undefined method > `delive_to_send_mail_to_online_user_on_ticket_creation'' > for SDMailer:Class >rescues can go in other places, eg def some_method ... rescue ... ... end so for example you can do def some_method begin ... end rescue ... end end Although the use of a begin/end block doesn''t really add anything. Fred> > Sijo > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---