Hello, I have been trying to do something like this.. I have an object which is being sent through to the view from the controller and since the object is not guarenteed to have non nil values, i use an exception handler to catch the exception upto which this works fine. However in the handler, I need to redirect to say an error page, it says "undefined method redirect_to". The snippet from my view : <%begin %> ... ....<some code that might give exception> ... <% end %> <%rescue => msg %> <% logger.info "Exception occurred - " + msg.to_s %> <%= redirect_to :controller => ''my_controller'', :action => ''error'' %> <%end %> This view is rendered thorough another action from the same controller ''my_controller''. When an exception occurs, it is caught and the point upto which the exception is rendered correctly. However, I would want the page to be redirected rather than being partially rendered. Is there anything that I am doing incorrectly here ? Any suggestions on this would be really helpful. ~Titan. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Seems to me as if you''re having much too much logic in that view. Such decisions should be made in the controller The view should only display results. --~--~---------~--~----~------------~-------~--~----~ 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 26 Jun 2008, at 12:24, Titan wrote:> > > This view is rendered thorough another action from the same controller > ''my_controller''. When an exception occurs, it is caught and the point > upto which the exception is rendered correctly. However, I would want > the page to be redirected rather than being partially rendered. Is > there anything that I am doing incorrectly here ? Any suggestions on > this would be really helpful. >you can''t redirect from the view. You might be able to use a rescue_from handler in your controller, although I think the approach you''re taking is a bit fugly. Fred>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The issue you are having here is that you are trying to save yourself specific checks by using a global begin rescue block. so if you dont have guranteed values. (I.e: columns which are not checked for presence) and want to display them in the view then you should do something like: <%= @model.columnname.uppercase if @model.columname %> to avoid the error. "Undefined method uppercase for nil object" yes, every time. ps: you have your begin rescue bblock wrong. begin code_that_might_raise rescue Exception => e more_code end AND NOT begin code_that_might_raise end <-------------- this is wrong. rescue Exception => e more_code end Hope it heps On Jun 26, 12:24 pm, Titan <shankarp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The snippet from my view : > > <%begin %> > ... > ....<some code that might give exception> > ... > > <% end %> > <%rescue => msg %> > <% logger.info "Exception occurred - " + msg.to_s %> > <%= redirect_to :controller => ''my_controller'', :action => ''error'' %> > <%end %> > > This view is rendered thorough another action from the same controller > ''my_controller''. When an exception occurs, it is caught and the point > upto which the exception is rendered correctly. However, I would want > the page to be redirected rather than being partially rendered. Is > there anything that I am doing incorrectly here ? Any suggestions on > this would be really helpful. > > ~Titan.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Does a rescue_from in the controller rescue exceptions in the view? I had problems with this a while back and just assumed it didn''t. RSL On Thu, Jun 26, 2008 at 7:31 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 26 Jun 2008, at 12:24, Titan wrote: > > > > > > This view is rendered thorough another action from the same controller > > ''my_controller''. When an exception occurs, it is caught and the point > > upto which the exception is rendered correctly. However, I would want > > the page to be redirected rather than being partially rendered. Is > > there anything that I am doing incorrectly here ? Any suggestions on > > this would be really helpful. > > > you can''t redirect from the view. You might be able to use a > rescue_from handler in your controller, although I think the approach > you''re taking is a bit fugly. > > Fred > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for all your quick thoughts on this. What Wolas had predicted is exactly the case that I am facing(a large set of legacy data); for which I wanted to have a global rescue blocks. But I had earlier faced some problems with rescue_from while dealing with the views and so I guess I would have to have individual validations for the fields before rendering them. thanks! ~Titan. On Jun 26, 4:54 pm, "Russell Norris" <r...-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote:> Does a rescue_from in the controller rescue exceptions in the view? I had > problems with this a while back and just assumed it didn''t. > > RSL > > On Thu, Jun 26, 2008 at 7:31 AM, Frederick Cheung < > > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 26 Jun 2008, at 12:24, Titan wrote: > > > > This view is rendered thorough another action from the same controller > > > ''my_controller''. When an exception occurs, it is caught and the point > > > upto which the exception is rendered correctly. However, I would want > > > the page to be redirected rather than being partially rendered. Is > > > there anything that I am doing incorrectly here ? Any suggestions on > > > this would be really helpful. > > > you can''t redirect from the view. You might be able to use a > > rescue_from handler in your controller, although I think the approach > > you''re taking is a bit fugly. > > > Fred > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 26 Jun 2008, at 12:54, Russell Norris wrote:> Does a rescue_from in the controller rescue exceptions in the view? > I had problems with this a while back and just assumed it didn''t. >can''t remember, which is why I said might :-). It seems that any exception thrown while rendering is wrapped inside an ActionView::TemplateError and so that''s the type you have to rescue_from (which seems to work in a quick experiment) Fred> RSL > > On Thu, Jun 26, 2008 at 7:31 AM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > wrote: > > > On 26 Jun 2008, at 12:24, Titan wrote: > > > > > > This view is rendered thorough another action from the same > controller > > ''my_controller''. When an exception occurs, it is caught and the > point > > upto which the exception is rendered correctly. However, I would > want > > the page to be redirected rather than being partially rendered. Is > > there anything that I am doing incorrectly here ? Any suggestions > on > > this would be really helpful. > > > you can''t redirect from the view. You might be able to use a > rescue_from handler in your controller, although I think the approach > you''re taking is a bit fugly. > > Fred > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
aha! i''m sure that was it, i just wasn''t rescuing the right error. RSL On Thu, Jun 26, 2008 at 9:11 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 26 Jun 2008, at 12:54, Russell Norris wrote: > > > Does a rescue_from in the controller rescue exceptions in the view? > > I had problems with this a while back and just assumed it didn''t. > > > > can''t remember, which is why I said might :-). It seems that any > exception thrown while rendering is wrapped inside an > ActionView::TemplateError and so that''s the type you have to > rescue_from (which seems to work in a quick experiment) > > Fred > > > RSL > > > > On Thu, Jun 26, 2008 at 7:31 AM, Frederick Cheung < > frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > > wrote: > > > > > > On 26 Jun 2008, at 12:24, Titan wrote: > > > > > > > > > This view is rendered thorough another action from the same > > controller > > > ''my_controller''. When an exception occurs, it is caught and the > > point > > > upto which the exception is rendered correctly. However, I would > > want > > > the page to be redirected rather than being partially rendered. Is > > > there anything that I am doing incorrectly here ? Any suggestions > > on > > > this would be really helpful. > > > > > you can''t redirect from the view. You might be able to use a > > rescue_from handler in your controller, although I think the approach > > you''re taking is a bit fugly. > > > > Fred > > > > > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---