how to sort joined tables?

help please write orm-request.

tables: users: id: integer name: varchar

posts: id: integer title: varchar user_id: integer views: integer

models: User: class User < ActiveRecord::Base   has_many :posts, dependent: :destroy end

Posts: class Post < ActiveRecord::Base   belongs_to :user end

controller: def popular_diary   @users = User.joins(:posts).group_by(:user_id).order('SUM(posts.views)') end

html:   <% @users.each do |user| %>     <div class="row">       <%= link_to user_posts_url(user.id) do %>         <div><%= user.name %></div>       <% end %>     </div>   <% end %>

I need that all users hatched in a certain order. order ('SUM (posts.views)

The problem is that the screen displays the following error message: wrong number of arguments (0 for 1)

Look near the error message it will show you what line the error occurred at.

tamouse m. wrote in post #1175655:

Look near the error message it will show you what line the error occurred at.

http://joxi.ru/1A5RvGah55YwrE

sorry. i replace 'group_by' on 'group' and it worked)