This is my loop. On my region page I show all the cities with there activities, events etc
- @cities.each do |city|
%li
%h4.h6.icon_mappoint
= link_to city.name, region_city_path(@region, city)
%ul
- city.events.each do |thing|
%li
= link_to event.name, region_city_event_path(@region, city, event)
%ul
- city.activities.each do |activity|
%li
= link_to activity.name, region_city_activity_path(@region, city, activity)
Each event and activity model has a attribute in the DB called active. (boolean). And want to show only the active events and activities in the view.
My controller looks like this now.
def show
@region = Region.find(params[:id])
@cities = @region.cities
end
Models
region has_many cities
city has_many events, activities
How can I show only the active events, activities in the each loop?
If you add a scope to your
EventandActivitymodelsyou can write your views like
and