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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.