I''m trying to extend Enumerable in my Rails app. I''ve started with just the controller where I wanted to use this method i.e. class LookupController < ApplicationController module Enumerable def my_compress .... ... but when I visit the web page in question I get "No method ''my_compress'' for Array ..." I''m probably doing something fundamentally wrong - what could/should I be doing? thanks -- 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-/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.
Toby Rodwell wrote:> I''m trying to extend Enumerable in my Rails app. I''ve started with just > the controller where I wanted to use this method i.e. > > class LookupController < ApplicationController > > module Enumerable > def my_compress > .... > > ... but when I visit the web page in question I get "No method > ''my_compress'' for Array ..." > > I''m probably doing something fundamentally wrong - what could/should I > be doing?You should be putting your model logic in the model, not in the controller.> > thanksBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/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 May 23, 12:59 am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > module Enumerable > > def my_compress > > .... > > > ... but when I visit the web page in question I get "No method > > ''my_compress'' for Array ..." > > > I''m probably doing something fundamentally wrong - what could/should I > > be doing? > > You should be putting your model logic in the model, not in the > controller. >on top of that, by putting it inside the controller like that you''ve created a new module called LookupController::Enumerable rather than extending Enumerable. If I were you I''d keep extensions to core classes somewhere in lib. Fred> > > > thanks > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > 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-/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 athttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On May 23, 12:59�am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > ... by putting it inside the controller like that you''ve > created a new module called LookupController::Enumerable rather than > extending Enumerable. If I were you I''d keep extensions to core > classes somewhere in lib. > > FredAh I see, of course. So I''ve moved it to ''my_extensions.rb'' in lib/, added "require ''my_extensions''" in the controller and now it works fine. Thanks! -- 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-/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.