The following code gives me an error: class_vars = [''fruit'',''cow'',''coffee''].each do |class_var| "#{class_var}".classify.send(:find, 1 + rand(10)) end The error message stack: LocalJumpError: no block given from (irb):34:in `find'' from (irb):33:in `each'' from (irb):33:in `find'' from (irb):33:in `send'' from (irb):33 from (irb):32:in `each'' from (irb):32 from :0 What I am trying to do here is, convert a string to an ActiveRecord class and then send a AR method like find to it. But it doesn''t work. I have all the classes defined. Any idea why this is happening? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 29 Dec 2007, at 12:21, Love AJAX wrote:> > The following code gives me an error: > class_vars = [''fruit'',''cow'',''coffee''].each do |class_var| > "#{class_var}".classify.send(:find, 1 + rand(10)) > end > > The error message stack: > LocalJumpError: no block given > from (irb):34:in `find'' > from (irb):33:in `each'' > from (irb):33:in `find'' > from (irb):33:in `send'' > from (irb):33 > from (irb):32:in `each'' > from (irb):32 > from :0 > > What I am trying to do here is, convert a string to an ActiveRecord > classIf you just poke around in the console you''ll see that ''fruit''.classify #=> ''Fruit'' That''s a string, not a Class (i.e. classify is just a string transformation that camelcases or whatever is has to do). You can use constantize to actually get the class you''re talking about. Fred> and then send a AR method like find to it. But it doesn''t work. > I have all the classes defined. > > Any idea why this is happening? > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It works. Thanks a lot. I should have tried this one. On 12/29/07, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 29 Dec 2007, at 12:21, Love AJAX wrote: > > > > > The following code gives me an error: > > class_vars = [''fruit'',''cow'',''coffee''].each do |class_var| > > "#{class_var}".classify.send(:find, 1 + rand(10)) > > end > > > > The error message stack: > > LocalJumpError: no block given > > from (irb):34:in `find'' > > from (irb):33:in `each'' > > from (irb):33:in `find'' > > from (irb):33:in `send'' > > from (irb):33 > > from (irb):32:in `each'' > > from (irb):32 > > from :0 > > > > What I am trying to do here is, convert a string to an ActiveRecord > > class > If you just poke around in the console you''ll see that > ''fruit''.classify #=> ''Fruit'' > That''s a string, not a Class (i.e. classify is just a string > transformation that camelcases or whatever is has to do). > You can use constantize to actually get the class you''re talking about. > > Fred > > > and then send a AR method like find to it. But it doesn''t work. > > I have all the classes defined. > > > > Any idea why this is happening? > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---