tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org
2009-Mar-27 01:33 UTC
Method not available within same module as definition
# This will probably be embarrassingly obvious. It acts as if it''s an # evaluation order issue (like the method call is happening prior to the # method definition). But that isn''t the case. The model_names method # works fine on the console. I''m missing a core concept obviously. # Error message from test tylers-mbpro:test tyler$ ruby helpers/application_helper_test.rb /Users/tyler/versioned/tma-code/rails/facilit-e/app/helpers/application_helper.rb:23: undefined local variable or method `model_names'' for ApplicationHelper:Module (NameError) # ApplicationHelper module ApplicationHelper def self.make_user_select_collects(assoc_id_param) module_eval %{ def select_collect_by_#{assoc_id_param}(klass, assoc_id, order_by_col=''full_name'') klass.find_all_by_#{assoc_id_param}(assoc_id, :order => order_by_col.to_sym).collect {|s| [s.full_name, s.id]} end } end def self.model_names models = Array.new Dir["app/models/**/*.rb"].each do |f| models << File.basename(f).sub(/.rb$/,'''').titlecase.gsub(/\s/,'''').constantize end models end ids = Array.new model_names.each do |klass| #model_names klass.column_names.grep(/_id$/).each do |assoc_id| unless ids.member?(assoc_id) ids << assoc_id make_user_select_collects(assoc_id) end end end end # Thanks for any help -- Thanks, Tyler Arrigoni President OneInterface.net Network Engineering, Inc. 7475 North Palm, Suite 105, Fresno, CA 93711 Voice: 559-437-3750 ext. 110 Cell: 559-696-0400 Fax1: 866-691-5145 (confidential) Fax2: 559-437-3754 (non-confidential) Email: tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org GnuPG: http://www.oneinterface.net/crypt/tyler.asc --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Conrad Taylor
2009-Mar-27 08:30 UTC
Re: Method not available within same module as definition
On Thu, Mar 26, 2009 at 6:33 PM, <tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org> wrote:> > # This will probably be embarrassingly obvious. It acts as if it''s an > # evaluation order issue (like the method call is happening prior to the > # method definition). But that isn''t the case. The model_names method > # works fine on the console. I''m missing a core concept obviously. > > # Error message from test > tylers-mbpro:test tyler$ ruby helpers/application_helper_test.rb > > /Users/tyler/versioned/tma-code/rails/facilit-e/app/helpers/application_helper.rb:23: > undefined local variable or method `model_names'' for > ApplicationHelper:Module (NameError) > > # ApplicationHelper > module ApplicationHelper > > def self.make_user_select_collects(assoc_id_param) > module_eval %{ > def select_collect_by_#{assoc_id_param}(klass, assoc_id, > order_by_col=''full_name'') > klass.find_all_by_#{assoc_id_param}(assoc_id, > :order => order_by_col.to_sym).collect {|s| [s.full_name, s.id]} > end > } > end > > def self.model_names > models = Array.new > Dir["app/models/**/*.rb"].each do |f| > models << > File.basename(f).sub(/.rb$/,'''').titlecase.gsub(/\s/,'''').constantize > end > models > end > > ids = Array.new > model_names.each do |klass| #model_names > klass.column_names.grep(/_id$/).each do |assoc_id| > unless ids.member?(assoc_id) > ids << assoc_id > make_user_select_collects(assoc_id) > end > end > end > > end > > # Thanks for any help > > -- > Thanks, > > Tyler Arrigoni > President > > OneInterface.net Network Engineering, Inc. > 7475 North Palm, Suite 105, Fresno, CA 93711 > Voice: 559-437-3750 ext. 110 > Cell: 559-696-0400 > Fax1: 866-691-5145 (confidential) > Fax2: 559-437-3754 (non-confidential) > Email: tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org > GnuPG: http://www.oneinterface.net/crypt/tyler.asc >Tyler, I wasn''t able to reproduce the error message above using this simplified example: module ApplicationHelper def self.make_user_select_collects(assoc_id_param) module_eval %{ def select_collect_by_#{assoc_id_param}(klass, assoc_id, order_by_col=''full_name'') klass.find_all_by_#{assoc_id_param}(assoc_id, :order => order_by_col.to_sym).collect {|s| [s.full_name, s.id]} end } end def self.model_names models = Array.new Dir["app/models/**/*.rb"].each do |f| models << File.basename(f).sub(/.rb$/,'''').titlecase.gsub(/\s/,'''').constantize end models end ids = Array.new model_names.each do |klass| #model_names klass.column_names.grep(/_id$/).each do |assoc_id| unless ids.member?(assoc_id) ids << assoc_id # make_user_select_collects(assoc_id) end end end puts "Model #{self} completed" end darnoc-desktop:app conradwt$ ruby helpers/application_helper.rb => Model ApplicationHelper completed BTW, I used Ruby 1.9.1 to execute the above code. I''ll try the above on my laptop using Ruby 1.8.6 to see if it''s consistent with Ruby 1.9.1. -Conrad --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org
2009-Mar-27 09:16 UTC
Re: Method not available within same module as definition
Conrad, Interesting...please do let me know your results with 1.8.6. Thanks, Tyler Arrigoni President OneInterface.net Network Engineering, Inc. 7475 North Palm, Suite 105, Fresno, CA 93711 Voice: 559-437-3750 ext. 110 Cell: 559-696-0400 Fax1: 866-691-5145 (confidential) Fax2: 559-437-3754 (non-confidential) Email: tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org GnuPG: http://www.oneinterface.net/crypt/tyler.asc -------- Original Message -------- Subject: [Rails] Re: Method not available within same module as definition From: Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Date: 3/27/09 1:30 AM> On Thu, Mar 26, 2009 at 6:33 PM, <tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org > <mailto:tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org>> wrote: > > > # This will probably be embarrassingly obvious. It acts as if it''s an > # evaluation order issue (like the method call is happening prior to the > # method definition). But that isn''t the case. The model_names method > # works fine on the console. I''m missing a core concept obviously. > > # Error message from test > tylers-mbpro:test tyler$ ruby helpers/application_helper_test.rb > /Users/tyler/versioned/tma-code/rails/facilit-e/app/helpers/application_helper.rb:23: > undefined local variable or method `model_names'' for > ApplicationHelper:Module (NameError) > > # ApplicationHelper > module ApplicationHelper > > def self.make_user_select_collects(assoc_id_param) > module_eval %{ > def select_collect_by_#{assoc_id_param}(klass, assoc_id, > order_by_col=''full_name'') > klass.find_all_by_#{assoc_id_param}(assoc_id, > :order => order_by_col.to_sym).collect {|s| [s.full_name, s.id > <http://s.id>]} > end > } > end > > def self.model_names > models = Array.new > Dir["app/models/**/*.rb"].each do |f| > models << > File.basename(f).sub(/.rb$/,'''').titlecase.gsub(/\s/,'''').constantize > end > models > end > > ids = Array.new > model_names.each do |klass| #model_names > klass.column_names.grep(/_id$/).each do |assoc_id| > unless ids.member?(assoc_id) > ids << assoc_id > make_user_select_collects(assoc_id) > end > end > end > > end > > # Thanks for any help > > -- > Thanks, > > Tyler Arrigoni > President > > OneInterface.net Network Engineering, Inc. > 7475 North Palm, Suite 105, Fresno, CA 93711 > Voice: 559-437-3750 ext. 110 > Cell: 559-696-0400 > Fax1: 866-691-5145 (confidential) > Fax2: 559-437-3754 (non-confidential) > Email: tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org <mailto:tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org> > GnuPG: http://www.oneinterface.net/crypt/tyler.asc > > > Tyler, I wasn''t able to reproduce the error message above using this > simplified example: > > module ApplicationHelper > > def self.make_user_select_collects(assoc_id_param) > module_eval %{ > def select_collect_by_#{assoc_id_param}(klass, assoc_id, > order_by_col=''full_name'') > klass.find_all_by_#{assoc_id_param}(assoc_id, > :order => order_by_col.to_sym).collect {|s| [s.full_name, s.id > <http://s.id>]} > end > } > end > > def self.model_names > models = Array.new > Dir["app/models/**/*.rb"].each do |f| > models << > File.basename(f).sub(/.rb$/,'''').titlecase.gsub(/\s/,'''').constantize > end > models > end > > ids = Array.new > model_names.each do |klass| #model_names > klass.column_names.grep(/_id$/).each do |assoc_id| > unless ids.member?(assoc_id) > ids << assoc_id > # make_user_select_collects(assoc_id) > end > end > end > > puts "Model #{self} completed" > > end > > darnoc-desktop:app conradwt$ ruby helpers/application_helper.rb > > => Model ApplicationHelper completed > > BTW, I used Ruby 1.9.1 to execute the above code. I''ll try the above on > my laptop using > Ruby 1.8.6 to see if it''s consistent with Ruby 1.9.1. > > -Conrad > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Conrad Taylor
2009-Mar-27 11:14 UTC
Re: Method not available within same module as definition
On Fri, Mar 27, 2009 at 2:16 AM, <tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org> wrote:> > Conrad, > > Interesting...please do let me know your results with 1.8.6. > > Thanks, > > Tyler Arrigoni > President > > OneInterface.net Network Engineering, Inc. > 7475 North Palm, Suite 105, Fresno, CA 93711 > Voice: 559-437-3750 ext. 110 > Cell: 559-696-0400 > Fax1: 866-691-5145 (confidential) > Fax2: 559-437-3754 (non-confidential) > Email: tyler-x6HOQYo3xDg4mGHdZ9yRmg@public.gmane.org > GnuPG: http://www.oneinterface.net/crypt/tyler.asc >Tyler, I''m seeing the same result using Ruby 1.8.6. BTW, here''s the exact version that I''m running in regards to 1.8.6: ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-darwin9.6.0] -Conrad --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---