In my model I've defined:
scope :active, -> { where(active: 'true') }
And my controller
def index
if logged_in?
@objects = Objects.all
else
@objects = Objects.active
end
end
In my index view, when logged_in? is true, I get all records as expected, but otherwise, I get nothing (I know at least one record is active).
Have I written my scope incorrectly?
It should be
scope :active, -> { where(active: true) }
Note: true
is not enclosed in quotes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.