Is there a way to DRY this up a bit? named_scope :has_valid_sysoid, lambda{|sysoid| (sysoid.nil?) ? {:conditions => ["nodesysoid IS NOT NULL AND nodelabel LIKE ''%-to-%''"], :include => [:ipinterface, :alarm]} : {:conditions => ["nodesysoid IS NOT NULL AND nodelabel LIKE ''%-to-%'' AND nodesysoid = ? ", sysoid], :include => [:ipinterface, :alarm]} } -- 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 Jun 24, 2010, at 3:34 PM, Me wrote:> Is there a way to DRY this up a bit? > > named_scope :has_valid_sysoid, lambda{|sysoid| > (sysoid.nil?) ? {:conditions => ["nodesysoid IS NOT NULL AND > nodelabel LIKE ''%-to-%''"], :include => [:ipinterface, :alarm]} : > {:conditions => ["nodesysoid IS NOT NULL AND nodelabel LIKE ''%-to-%'' > AND nodesysoid = ? ", sysoid], :include => [:ipinterface, :alarm]} > }You could move the condition inside the {}''s so it only affects the value of the :conditions key. But... I would be more included to separate the scopes into :has_valid_sysoid and :has_specific_sysoid. Model.has_valid_sysoid(''foo'') doesn''t really seem to be doing what the scope suggests it''s doing... to me anyway.. I see a difference b/n "valid" and "a specific". I don''t know if that makes sense for your application or not... -philip -- 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.
Thanks. Trying to keep the controller simple: Takes a value or not. One thing I could do was put he include inside the method call but where does the param go? Node.has_valid_sysoid(..) The scope is working, just trying cut out the duplication. On Jun 24, 5:57 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> On Jun 24, 2010, at 3:34 PM, Me wrote: > > > Is there a way to DRY this up a bit? > > > named_scope :has_valid_sysoid, lambda{|sysoid| > > (sysoid.nil?) ? {:conditions => ["nodesysoid IS NOT NULL AND > > nodelabel LIKE ''%-to-%''"], :include => [:ipinterface, :alarm]} : > > {:conditions => ["nodesysoid IS NOT NULL AND nodelabel LIKE ''%-to-%'' > > AND nodesysoid = ? ", sysoid], :include => [:ipinterface, :alarm]} > > } > > You could move the condition inside the {}''s so it only affects the value of the :conditions key. > > But... I would be more included to separate the scopes into :has_valid_sysoid and :has_specific_sysoid. > > Model.has_valid_sysoid(''foo'') doesn''t really seem to be doing what the scope suggests it''s doing... to me anyway.. I see a difference b/n "valid" and "a specific". > > I don''t know if that makes sense for your application or not... > > -philip-- 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.
named_scope :has_valid_sysoid, lambda{|sysoid| conditions = ["nodesysoid IS NOT NULL AND nodelabel LIKE ''%-to-%''] unless sysoid.nil? conditions[0]<< " AND nodesysoid = ?" conditions << sysoid end {:conditions => conditions, :include => [:ipinterface, :alarm]} } <zitiere wer="Me">> Thanks. > > Trying to keep the controller simple: > Takes a value or not. > One thing I could do was put he include inside the method call but > where does the param go? > > Node.has_valid_sysoid(..) > > The scope is working, just trying cut out the duplication. > > On Jun 24, 5:57 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: >> On Jun 24, 2010, at 3:34 PM, Me wrote: >> >> > Is there a way to DRY this up a bit? >> >> > named_scope :has_valid_sysoid, lambda{|sysoid| >> > (sysoid.nil?) ? {:conditions => ["nodesysoid IS NOT NULL AND >> > nodelabel LIKE ''%-to-%''"], :include => [:ipinterface, :alarm]} : >> > {:conditions => ["nodesysoid IS NOT NULL AND nodelabel LIKE ''%-to-%'' >> > AND nodesysoid = ? ", sysoid], :include => [:ipinterface, :alarm]} >> > } >> >> You could move the condition inside the {}''s so it only affects the >> value of the :conditions key. >> >> But... I would be more included to separate the scopes into >> :has_valid_sysoid and :has_specific_sysoid. >> >> Model.has_valid_sysoid(''foo'') doesn''t really seem to be doing what the >> scope suggests it''s doing... to me anyway.. I see a difference b/n >> "valid" and "a specific". >> >> I don''t know if that makes sense for your application or not... >> >> -philip > > -- > 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. > >-- Herr Bente Pieck, Weidenallee 37 20357, Hamburg Tel.: 0152-22361035 -- 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.
Reasonably Related Threads
- Problem with named_scope
- Re old message CPQPOWER-MIB - nearly there (using snmp-ups with HP AH401A management card)
- deprecation warning in Rails 3 about Base.named_scope
- Tripplite UPS (SU10KRT3/1X) through snmp-ups (nut 2.6.5)
- Arch Linux and Tripp Lite web snmp card issues.