Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > BOOK: Ruby on Rails for Microsoft Developers
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #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

Hi Dave,

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

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:

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:

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.

  #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

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 01:18 PM.

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