On 29 June 2014 22:26, Fresh Mix <lists@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
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsgs-Gb8dNGyRcfh6YB75a0CpkZEz7GyRZ%2BdjpcY-prJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment