Hi In an action in admin_controller, I called a method in the model ci.rb The code is shown below: In controller: can_delete = Ci.is_ci_class_in_use(ci_type, @ci_classes) Then in model: class Ci < ActiveRecord::Base def self.is_ci_class_in_use(ci_type,ci_classes) @cis=self.find_all_by_citype(ci_type.to_s) for ci in @cis for ci_class in ci_classes if ci.content.ci_class.to_i == ci_class.id.to_i can_delete = 0 ci_number = ci.ci_number break else can_delete = 1 end break if can_delete==0 end break if can_delete==0 end return # I have to return two variables can_delete and ci_number here. end end How can I return the two variables can_delete and ci_number? Please help. Thanks Regards Suneeta -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Unnikrishnan Kp wrote:> Why dont you return it as an Array? - return [can_delete,ci_number] > > On Jun 24, 11:09 am, Suneeta Km <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Hi Thank you for your help. I tried returning it as an array. Then I printed it in the console to see how it is returned. can_delete = Ci.is_ci_class_in_use(ci_type, @ci_classes) puts "the value returned is: " +can_delete.to_s It printed: the value returned is: 0CI15 The value of can_delete = 0 and ci_number = CI15 How can I retrieve these values from the returned array? Thanks Suneeta -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Alagesa Pandian
2008-Jun-24 06:38 UTC
Re: How to return more than one value from a function?
return as hash or array return {:can_delete => 0, :ci_number => what_ever_the_number} -pandian On Tue, Jun 24, 2008 at 11:39 AM, Suneeta Km < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi > > In an action in admin_controller, I called a method in the model ci.rb > The code is shown below: > > In controller: > can_delete = Ci.is_ci_class_in_use(ci_type, @ci_classes) > > Then in model: > > class Ci < ActiveRecord::Base > > def self.is_ci_class_in_use(ci_type,ci_classes) > @cis=self.find_all_by_citype(ci_type.to_s) > for ci in @cis > for ci_class in ci_classes > if ci.content.ci_class.to_i == ci_class.id.to_i > can_delete = 0 > ci_number = ci.ci_number > break > else > can_delete = 1 > end > break if can_delete==0 > end > break if can_delete==0 > end > return # I have to return two variables can_delete and > ci_number here. > end > end > > How can I return the two variables can_delete and ci_number? > Please help. > > Thanks > Regards > Suneeta > -- > Posted via http://www.ruby-forum.com/. > > > ><http://mapunity.in> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thank you.. it works. I returned it as an array -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe
2008-Jun-24 10:44 UTC
Re: How to return more than one value from a function?
Suneeta Km wrote:> thank you.. it works. I returned it as an arrayYou can also just use more than one variable on the receiving end and send each value back independently (not in an array). var_1, var_2 = some_method def some_method return ''hi'', ''there'' end Peace, Phillip -- 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-/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 -~----------~----~----~----~------~----~------~--~---