On 20 September 2011 12:30, Mathew Vivek <[email protected]> wrote:
> Hi,
>
>  I want to sort a array objects which depends upon relationships between
> two tables.
>
> table 1 : comments
> table 2 : comments_date
>
> Once a comment is added, the date which it is created will be saved in
> comments date table.. now i want to sort the
>
> comments array with respect to date it is created..
>
> the code looks like this..
>
>
> @comments.sort_by do |a|
>    a.comments_date
> end

It would be more efficient to sort it when you get it from the db.  So
in the find use something like :include => :comments_dates and then
have an order clause specifying comments_dates.date (or whatever the
column is called in the comments_dates table.

I have to agree with Tim that it seems odd to have a separate table
for the date rather than just a column in the comments table.

Colin
>
> thanks in advance
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>



-- 
gplus.to/clanlaw

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to