Please help me out

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.

Thanks in advance.

If you like ruby queries like me then you can use
User.where(street: nil)

On 23 December 2014 at 14:49, lekha p. [email protected] 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