Hi, I have a set of image tags which I use frequently in my views, so I want to gather these tags for reuse, something like: module ApplicationHelper ICON = { :email => image_tag(''/images/icons/email.gif'', {''title'' => ''Send Email''}), :arrow_up => image_tag(''/images/icons/arrowup.gif''), :arrow_down => image_tag(''/images/icons/arrowup.gif'') } End Then in a view, I would replace: <%= image_tag ''/images/icons/email.gif'', {''title'' => ''Send Email''} %> With the simpler: <%= ICON[:email] %> But when I try this, I get an error - NoMethodError (undefined method `image_tag'' for ApplicationHelper:Module) So two questions: 1) whats the best way to make tag helpers available to the helper ? 2) is there a better way to gather by my ''static'' view assets and so DRY Thanks, Nev
On Jun 23, 2005, at 7:40 PM, Neville Burnell wrote:> Hi, > > I have a set of image tags which I use frequently in my views, so I > want > to gather these tags for reuse, something like: > > module ApplicationHelper > > ICON = { :email => image_tag(''/images/icons/email.gif'', {''title'' => > ''Send Email''}), > :arrow_up => image_tag(''/images/icons/arrowup.gif''), > :arrow_down => image_tag(''/images/icons/arrowup.gif'') > } > > End >The problem is that ICON is being evaluated at the class level, and image_tag (and friends) are instance-level methods. You could do: def icon(which) case which when :email image_tag(''/images/icons/email.gif'', {''title'' => ''Send Email''}) when :arrow_up image_tag(''/images/icons/arrowup.gif'') when :arrow_down image_tag(''/images/icons/arrowup.gif'') end end - Jamis
> The problem is that ICON is being evaluated at the class level, andimage_tag (and friends) are instance-level methods. aha, I get it ... Thanks Jamis -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Jamis Buck Sent: Friday, 24 June 2005 11:49 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] Using AssetTagHelpers in a helper The problem is that ICON is being evaluated at the class level, and image_tag (and friends) are instance-level methods. You could do: def icon(which) case which when :email image_tag(''/images/icons/email.gif'', {''title'' => ''Send Email''}) when :arrow_up image_tag(''/images/icons/arrowup.gif'') when :arrow_down image_tag(''/images/icons/arrowup.gif'') end end - Jamis _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails