How many views every blog have?
Result should be:: blog_id, blog_name, visits_count
If you iterate through the blogs then for each blog
visits_count = blog.visits.count
and obviously the id and name are blog.id and blog.name. However if
you find yourself using the id then you are probably not doing
something the best way, it is unusual to have to reference the id
directly.
How many times each page has been accessed?
Result should be: page_id, page_title, page_data, visits_count
If you understand the answer above then I am sure you can work this one out.
The fact that you have asked this suggests that you are a beginner at
rails, in which case I suggest you work right through a good tutorial
such as railstutorial.org (which is free to use online). Then you
should understand the basics of rails.
Think about it. page.visits is an activerecord association
(effectively an array) of visits. You can call count on that which
tells you how many in the array, but you can't call liked as that is a
member of a single Visit object. You can call where() on an
association however and then call count on that, so that is one way to
do it. How are you getting on with the tutorial? It would answer all
these basic questions for you so we do not need to use our time
helping you when you could help yourself.