Forum: Ruby on Rails ActiveRecord method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
999d91164c5bc1ffeceb2319350416e4?d=identicon&s=25 Yusuke Enomoto (Guest)
on 2012-07-04 08:58
(Received via mailing list)
Hello.I have a question.  I am making chat application to practice RoR.

I have three models. User, Chat, and Message.
The relationship is that User has many chats(it means chat's host) and
many
message,s  Chat has many messages.

Now I want to create a lobby page like this.
http://freezing-sword-4391.herokuapp.com/chat/lobby

This page shows all chats sorted by the last message's created_at. each
chat shows who is chat's host, and what the last message is.

Is there any good way to get resource by ActiveRecord's method?

Besides, the amount of messages will be huge,so is there good way to get
all chats which have the last message by loading LIMIT 1 message?
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2012-07-04 10:23
(Received via mailing list)
On 3 July 2012 15:56, Yusuke Enomoto <mosaafi@gmail.com> wrote:
> shows who is chat's host, and what the last message is.
>
> Is there any good way to get resource by ActiveRecord's method?

Sorry, I don't understand the question.
Have you worked right through some tutorials (railstutorial is good
and is free to use online) to understand the basics of rails?  If not
then I suggest you do this.

>
> Besides, the amount of messages will be huge,so is there good way to get all
> chats which have the last message by loading LIMIT 1 message?

You can fetch just the first record of a query by using .first

Colin
This topic is locked and can not be replied to.