How to pass model names? The scenario is that i have written a function in application_hepler.rb as like.. def all_record_ids(model_name) all_records = model_name.all.find_all { |record| record.status == "ACTIVE" } end I am calling this function as like [ all_record_ids("Employee") ] but instead of getting result i am getting error as [ "undefined method `all'' for "Employee":String" ] So what is wrong here .. ? Can you guys light me up some direction ? -- 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 28 April 2010 11:23, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> How to pass model names? >def all_record_ids(model_name) all_records = model_name.constantize.all.find_all { |record| record.status == "ACTIVE" } end -- 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.
Michael Pavling wrote:> def all_record_ids(model_name) > �all_records = model_name.constantize.all.find_all { > � �|record| record.status == "ACTIVE" > �} > endThanks dude.. It worked like a charm.. i was not aware of this keyword.. :) -- 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.
On 28 April 2010 11:45, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Thanks dude.. It worked like a charm.. i was not aware of this keyword..It''s one of the Inflector methods... well worth being familiar with them: http://api.rubyonrails.org/classes/Inflector.html -- 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.