Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Ruby on Rails for Microsoft Developers
This is the forum to discuss the Wrox book Ruby on Rails for Microsoft Developers by Antonio Cangiano; ISBN: 9780470374955
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ruby on Rails for Microsoft Developers section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 21st, 2009, 08:41 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default name_scope section page 188 & 189

Hi Everyone,

I'm wondering if anyone can explain the change in @articles across pages 188 and 189 where the :conditions is introduced and the :published => true becomes published = ? AND etc....

I don't understand the code here and would appreciate an explanation...
More specifically why has this changed from :published => true to published => ?
( no colon, becomes a questions mark )
Also why is this section in square brackets where the previous version is using curly brackets.

regards, Dave Porter
  #2 (permalink)  
Old October 8th, 2009, 05:45 PM
Registered User
 
Join Date: Apr 2009
Location: Toronto, Canada
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
Smile

Hi Dave,

in that section I employed two different ways of specifying conditions. The simplest one is to use a hash:

Code:
Article.find(:all, :conditions => { :published => true }, :order => "published_at DESC")
This can also be expressed as an array whose first element is a string containing the parameterized condition. For example, the line above could be rewritten as follows:

Code:
Article.find(:all, :conditions => ["published = ?", true], :order => "published_at DESC")
Using an array is more flexible than a hash, because you can specify the condition however you wish. The hash only allows you to specify an exact value to match one or more columns.

In fact, later in the same section of the book I used:

Code:
Article.find(:all, :conditions => [“published = ? AND published_at <= ?”, true, Time.now.utc], :order => “published_at DESC”)
Notice how published_at is compared with <=. You couldn't express this with the hash syntax.

I hope this helps clarify the issue for you. If it doesn't, please don't hesitate to ask further questions.

Cheers,
Antonio
  #3 (permalink)  
Old October 9th, 2009, 03:14 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Antonio - that all makes sense now, thanks for your response...

Dave


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sphere - class or object on pg 189 Tracey BOOK: Beginning Java 2 0 July 24th, 2008 09:33 AM
page layout breaks in IE 6 & 7 Cyber Shiva CSS Cascading Style Sheets 0 July 5th, 2008 09:19 AM
Page 424 & 425 davidron BOOK: Professional Java Development with the Spring Framework 0 October 3rd, 2006 06:44 PM
Force Section to Page Bottom dsentelle VB.NET 2002/2003 Basics 2 August 14th, 2006 09:37 AM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.