PalaniKannan K
2011-Jan-31 16:34 UTC
Suggestion to reduce number of junk hierarchical ''if loops''
Hi, I have hierarchical "if loops" like this <% @descriptions.each_with_index do |description, i| %> <% description.tale2.each do |tax_ref| %> <% if condition %> <% if condition %> <% if condition %> <%= $text_first_describe%> <%= $paren_author_yr %> <% ref_sp_uniq.each_with_index do |ref, i| %> <% if ref =tax_ref.ref_wo_brace%> <% execution %> <% elsif i == (ref_sp_uniq.size - 1)%> <%# @ref_desc = "#{@ref_desc_numb}. #{tax_ref.ref_wo_brace}" %> <% end %> <% end %> <% if condition %> <% execution %> <% elsif condition %> <% execution %> <% elsif taxon_name.emend_author_year %> <%= print %> <% else %> <%= print %> <% end %> <% end %> <% else %> <% if condition %> <%= print %> <% ref_sp_uniq.each_with_index do |ref, i| %> <% if condition %> <% execution %> <% elsif condition %> <% execution %> <% end %> <% end %> <% if condition %> <% execution %> <% elsif condition %> <% execution %> <% elsif condition %> <% execution %> <% else %> <% execution %> <% end %> <% end %> <% end %> <% end %> <% end %> <% end %> Kindly suggest me possible way to reduce this kind of junk "if loops". -- 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.
David Kahn
2011-Jan-31 17:49 UTC
Re: Suggestion to reduce number of junk hierarchical ''if loops''
On Mon, Jan 31, 2011 at 10:34 AM, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hi, > > I have hierarchical "if loops" like this > > <% @descriptions.each_with_index do |description, i| %> <% > description.tale2.each do |tax_ref| %> > <% if condition %> > <% if condition %> <% if condition %> > <%= $text_first_describe%> <%= $paren_author_yr %> <% > ref_sp_uniq.each_with_index do |ref, i| %> <% if ref => tax_ref.ref_wo_brace%> <% execution %> > <% elsif i == (ref_sp_uniq.size - 1)%> <%# @ref_desc = "#{@ref_desc_numb}. > #{tax_ref.ref_wo_brace}" %> <% end %> <% end %> <% if condition %> <% > execution %> > <% elsif condition %> <% execution %> <% elsif taxon_name.emend_author_year > %> > <%= print %> <% else %> > <%= print %> > <% end %> <% end %> <% else %> <% if condition %> <%= print %> <% > ref_sp_uniq.each_with_index do |ref, i| %> <% if condition %> <% execution > %> > <% elsif condition %> <% execution %> > <% end %> <% end %> <% if condition %> <% execution %> > <% elsif condition %> <% execution %> > <% elsif condition %> <% execution %> > <% else %> <% execution %> > <% end %> <% end %> <% end %> <% end %> <% end %> > <% end %> >Hi Palani... first thing is find a way to move your logic to the Model. Your html.erb code really should be as much as possible just to present your data. Secondly, using the ''case'' construction might help: a = 1 case somthing when ''x'': do somthing when ''y'' do something else when ''z'' do another thing.... .... end> Kindly suggest me possible way to reduce this kind of junk "if loops". > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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.
PalaniKannan K
2011-Jan-31 18:03 UTC
Re: Suggestion to reduce number of junk hierarchical ''if loops''
Hi david, thanks for your suggestion. I tried ''case'' statement before. But, I am using ''if'' statements in the array loops of @descriptions and description.table2. @descriptions is an array generated in table 1''s controller. If I wish to ''use'' either table 1 or table 2 models... I am getting into problem to merge this two array loops. how i can use @desctipion (array generated in table1 controller) in the model of table 2? Kindly help this regard. -- with regards, palani kannan -- 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.
Ar Chron
2011-Jan-31 18:12 UTC
Re: Suggestion to reduce number of junk hierarchical ''if loops''
PalaniKannan K wrote in post #978680: You have a few paths which will yield nothing (no executions, no output). if !condition1 - nothing occurs if condition1 and condition2 and !condition3 - nothing occurs if condition1 and !condition2 and !condition6 - nothing occurs Scope your data access (either description or tale2) to eliminate those cases from the data considered, then simplify your logic. Less data to paw through with the rest of the code, and case might be a better construct for readability. BTW, what are all those execution steps? -- 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.
PalaniKannan K
2011-Jan-31 18:25 UTC
Re: Re: Suggestion to reduce number of junk hierarchical ''if loops''
Dear Ar Chron, these are hierarchial conditions. so i need in hierarchial lever... the conditions as well as execution content are "columns of @description from table1 and description.tale2". -- With Regards, Palani Kannan -- 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.
David Kahn
2011-Jan-31 18:35 UTC
Re: Suggestion to reduce number of junk hierarchical ''if loops''
On Mon, Jan 31, 2011 at 12:03 PM, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hi david, > > thanks for your suggestion. > > I tried ''case'' statement before. But, I am using ''if'' statements in the > array loops of @descriptions and description.table2. @descriptions is an > array generated in table 1''s controller. If I wish to ''use'' either table 1 > or table 2 models... I am getting into problem to merge this two array > loops. how i can use @desctipion (array generated in table1 controller) in > the model of table 2? Kindly help this regard. >I would think also you might be able to use includes or joins in your activerecord call, and/or a where condition to ''merge'' your results. Personally I would write out in pseudo-code what trying to do and then get as close to the db first (using activerecord in this case).> > -- > with regards, > > palani kannan > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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.
Matt Jones
2011-Feb-01 18:25 UTC
Re: Suggestion to reduce number of junk hierarchical ''if loops''
On Jan 31, 11:34 am, PalaniKannan K <kpalanikan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have hierarchical "if loops" like this >[snip]> > Kindly suggest me possible way to reduce this kind of junk "if loops". >Is there a reason you''re not using helpers and/or partials? They''re the standard Rails method of reducing complexity in views... --Matt Jones -- 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.