user6589814 user6589814 - 3 months ago 16
Ruby Question

Ruby on Rails - Add limit, order and sum on

In my application I have a

file that I
on users profile view. That
file contains some numbers.

This is what i have so far:

f ="public/users/14/user.txt", "r")
- f.each_line do |d|
%p= d

I can
out all the numbers that is on that file. Is it any way to add
order (start from bottom to top)

I tried:

f.limit(4).order('DESC').each_line do |d|

and"public/users/14/user.txt", "r").limit(5)

When I try these I get error:
undefined method limit
undefined method order

Is it also possible to
all the numbers on that file?


This should work:

@lines = IO.readlines('public/users/14/user.txt').sort.reverse.first(4)

You should put the above in your controller and use it in your view:

- @lines.each do |line|
  %p= line