Hi all, In one of my helpers I would like to call a redirect_to(url) action. I know the helpers are supposed almost only for formatting the view purposes but it''s the best way I have found to do what I want. If I call the redirect_to action in a helper I get the error: undefined method `redirect_to'' for #<#<Class:0x23aaedc>:0x23aaeb4> any solution for this? Thanks, Alvaro. -- 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 -~----------~----~----~----~------~----~------~--~---
There are some hackish ways. Let''s start with the basics though: What are you actually trying to do? Share that and someone can come up with the solution for you. If it''s a redirect, then it needs to be called from a controller. The best place to put that kinda stuff is the same place you put before_filters: in the controller itself as a protected method, or in app/controllers/application.rb as a protected method if you want all controllers to see it. (protected doesn''t *really* make it protected in the Java sense, it just makes it so it''s not a URL action, as all public methods in controllers become actions, especially if you leave the default routes in). -b On Jan 16, 2008 5:37 AM, Alvaro Perez <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi all, > > In one of my helpers I would like to call a redirect_to(url) action. I > know the helpers are supposed almost only for formatting the view > purposes but it''s the best way I have found to do what I want. If I call > the redirect_to action in a helper I get the error: > > undefined method `redirect_to'' for #<#<Class:0x23aaedc>:0x23aaeb4> > > any solution for this? > > > > Thanks, > Alvaro. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Brian Hogan wrote:> There are some hackish ways. Let''s start with the basics though: > > What are you actually trying to do? Share that and someone can come up > with > the solution for you. If it''s a redirect, then it needs to be called > from a > controller. The best place to put that kinda stuff is the same place you > put > before_filters: in the controller itself as a protected method, or in > app/controllers/application.rb as a protected method if you want all > controllers to see it. > > (protected doesn''t *really* make it protected in the Java sense, it just > makes it so it''s not a URL action, as all public methods in controllers > become actions, especially if you leave the default routes in). > > -b > > On Jan 16, 2008 5:37 AM, Alvaro Perez <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Hi Brian, yes I tried to call a redirect from within a helper, but after thinking twice I recognise that is a bad idea so I have rewritten the code to call it from the controller. Thank you anyway for the response. Alvaro. -- 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 -~----------~----~----~----~------~----~------~--~---