I am trying to sort an array after dato(date).
I have tried this without luck:
<%= Reklamer.where(:name => 'Orville', :order => 'dato ASC').all.map(&:earn) %>
And this:
<%= Reklamer.where(:name => 'Orville').all.map(&:earn).orde开发者_开发知识库r('dato ASC') %>
And:
<%= Reklamer.where(:name => 'Orville').order('dato ASC').all.map(&:earn) %>
And:
<%= Reklamer.where(:name => 'Orville').all.order('dato ASC').map(&:earn) %>
Try this:
<%= Reklamer.where(:name => 'Orville').order('dato ASC').map(&:earn).join(', ') %>
Though in general, I would recommend not putting all that data loading code into your view. Instead, push it to your models and controllers. For example, you could do this in your controller:
def show
@earnings = Reklamer.where(:name => 'Orville').order('dato ASC').map(&:earn)
end
Or, even better, push some of the more complicated stuff to your model:
class Reklamer
def self.earnings
where(:name => 'Orville').order('dato ASC').map(&:earn)
end
end
<%= Reklamer.find(:all, :conditions => {:name => 'Orville'}, :order => 'dato ASC', :select => 'sum(earn) AS earn', :group => 'dato').map(&:earn) %>
精彩评论