I''d like to know where exactly are helpers available by default? For example, if I have a PagesController, will my PagesHelper methods be available at PagesController? or just at the Pages''s views? Thank you, Rodrigo -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Helpers help generate code for the view. For example, if you have an array of items that need to be rendered in a specific way, you can encapsulate that functionality in a helper method, and call it from the view. It helps clean up the view code, and adds code reuse. So helpers are meant to be for views, not controllers. On Mon, Jul 11, 2011 at 1:06 PM, Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I''d like to know where exactly are helpers available by default? > > For example, if I have a PagesController, will my PagesHelper methods be > available at PagesController? or just at the Pages''s views? > > Thank you, > Rodrigo > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 11, 8:58 am, Dheeraj Kumar <a.dheeraj.ku...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Helpers help generate code for the view. For example, if you have an array > of items that need to be rendered in a specific way, you can encapsulate > that functionality in a helper method, and call it from the view. It helps > clean up the view code, and adds code reuse. So helpers are meant to be for > views, not controllers. > > On Mon, Jul 11, 2011 at 1:06 PM, Rodrigo Ruiz <rodrigo.ru...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > > > > > I''d like to know where exactly are helpers available by default? > > > For example, if I have a PagesController, will my PagesHelper methods be > > available at PagesController? or just at the Pages''s views?Dheeraj is correct, helpers are intended for views, but if you have a method that you need access to in your controller and your view, and/ or your helper then, in order to keep things a little DRYer, you can define your method in your controller, and make it available to the view and helper as so: class MyController < ApplicationController helper_method :my_method private def my_method # do something end end Now you can access my_method from your view or your helper as well as your controller. hth Paul> > > Thank you, > > Rodrigo > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.- Hide quoted text - > > - Show quoted text --- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 11 July 2011 08:36, Rodrigo Ruiz <rodrigo.ruiz7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''d like to know where exactly are helpers available by default? > For example, if I have a PagesController, will my PagesHelper methods be > available at PagesController? or just at the Pages''s views?In addition to other replies note that logic in controllers should rarely be sufficiently complex so as to require helpers. Such code should almost always be in the models. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.