You have a logic problem here, see this code:
# controller
@steppies_having_ask = Steppy.where("ask IS NOT NULL AND ask != ''").order('created_at DESC').limit(6)
@steppies_having_goal = Steppy.where('goal IS NOT NULL AND goal != ''').order('created_at DESC').limit(6)
# view
@steppies_having_goal.each do |steppy|
# display your steppy without testing `if steppy.goal.present?`
end
@steppies_having_ask.each do |steppy|
# display your steppy without testing `if steppy.ask.present?`
end
What is the logic problem you have?
- You get 6 records from the DB and loop on it,
- Then you display the record only if it has a value for the
ask
attribute (orgoal
)
What if the 6 records have no value for ask
(or goal
)? -> It would display nothing.