On 29 June 2014 22:26, Fresh Mix <
li...@ruby-forum.com> wrote:
> Tables:
>
> Blogs (id, name)
> Users (id, name)
> Pages (id, title, data)
> Visits (id, user_id, blog_id, page_id)
>
> 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.
Colin