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
Register
Register | 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 Display Modes
  #1 (permalink)  
Old September 21st, 2009, 09: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, 06: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, 04: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
 


Thread Tools
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 10:33 AM
page layout breaks in IE 6 & 7 Cyber Shiva CSS Cascading Style Sheets 0 July 5th, 2008 10:19 AM
Page 424 & 425 davidron BOOK: Professional Java Development with the Spring Framework 0 October 3rd, 2006 07:44 PM
Force Section to Page Bottom dsentelle VB.NET 2002/2003 Basics 2 August 14th, 2006 10: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 12:37 PM.


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