hi, <% @sp_references.each do |sp_ref| %> <% sp_ref.all_references.each_with_index do |tax_ref, i| %> <%if (tax_ref.reference.uniq) && (tax_ref.reference !~ /emend$/i) %> <%= tax_ref.reference %> <%end%> <%end%> <%end%> This ''uniq'' option to get distinct elements in tax_ref.reference is not working. It shows "undefined method `uniq'' for #<String:". Kindly help me this regard to get the distinct elements from array using each in rails. -- With Regards, Palani -- 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 Nov 29, 3:25 pm, PalaniKannan K <kpalanikan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, > > <% @sp_references.each do |sp_ref| %> > <% sp_ref.all_references.each_with_index do |tax_ref, i| %> > <%if (tax_ref.reference.uniq) && (tax_ref.reference !~ /emend$/i) %> > <%= tax_ref.reference %> > <%end%> > <%end%> > <%end%> > > This ''uniq'' option to get distinct elements in tax_ref.reference is not > working. It shows "undefined method `uniq'' for #<String:". Kindly help me > this regard to get the distinct elements from array using each in rails. >Sounds like tax_ref.refrence is a string, not an array so calling uniq on it doesn''t make any sense. Fred> -- > With Regards, > Palani-- 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.
Dear Fred, Yes I accept, any other way to extract the distinct content from each array? -- With Regards, Palani Kannan. K -- 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 29 November 2010 16:23, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes I accept, any other way to extract the distinct content from each array?Which array? The "sp_ref.all_references" array that you''re iterating, or a different one? Are you''re asking "how would I get a collection of distinct "reference" values from each collection of "sp_ref.all_references"? If so this might help... <% @sp_references.each do |sp_ref| %> <%= sp_ref.all_references.map(&:reference).uniq.delete_if{|ref| ref =~ /emend$/i}.join("<br/>") %> <% end %> ... you could break it apart into separate operations if you wished. -- 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.
Dear Michael, Thanks lot for your answer. <% @sp_references.each do |sp_ref| %>> <%= sp_ref.all_references.map(&:reference).uniq.delete_if{|ref| ref > =~ /emend$/i}.join("<br/>") %> > <% end %> >I need the results have to print without duplicates. This gives the results with duplicates. * <% @sp_references.each do |sp_ref| %> * * <%= sp_ref.all_references.map(&:reference).delete_if{|ref| ref=~ /emend$/i}.join("<br/>") %> <% end %>* and * <% @sp_references.each do |sp_ref| %> * * <%= sp_ref.all_references.map(&:reference).uniq.delete_if{|ref| ref=~ /emend$/i}.join("<br/>") %> <% end %>* presents same results with duplicates. Please about your suggestion. -- 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 30 November 2010 14:10, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need the results have to print without duplicates. This gives the results > with duplicates.<snip>> and<snip>> presents same results with duplicates. Please about your suggestion.I''m having trouble seeing where you''re even trying to explain what you have, and what you want.... Does this give what you''re after? : <%= @sp_references.map(&:all_references).flatten.map(&:reference).uniq.delete_if{|ref| ref=~ /emend$/i}.join("<br/>") %> To be honest, I''m just stabbing in the dark, because you''ve not explained anything about what these objects are made of or what actual end result you want to achieve... some pseudo-code would help... -- 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.