If you like ruby queries like me then you can use User.where(street: nil) On Tuesday, December 23, 2014 9:02:40 PM UTC+6, Colin Law wrote: > > On 23 December 2014 at 14:49, lekha p. <[email protected] <javascript:>> > wrote: > > Hi, > > > > I have a User Model which includes attributes Street, City. I want to > > get array of Streets of users, when street is blank or nil i want to > > pick up city of user. By searching i got to know i can get array of > > streets using > > User.pluck(:street), what is the query to find city of user when street > > is nil. > > Do you mean all the cities where the street is nil? If so then you > are going about it the wrong way. First you want to find all records > where the street is nil, so something like > User.where( "street is null" ) > That assumes you actually mean null entry rather than a blank string. > If you also mean a blank string then you can modify the where clause > appropriately. > Then you can extract the cities if you need to. > > I suspect that you may be beginner with Rails, in which case I > strongly urge you to work right through a good tutorial such as > railstutorial.org (which is free to use online). That will show you > the basics of rails, so avoiding the need to ask for help with basic > questions. > > Colin >
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d6d2c532-acce-412d-af84-e91c1aa56066%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

