ruby on rails - 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 |user| %> <div class="row"> <%= link_to user_posts_url(user.id) %> <div><%= user.name %></div> <% end %> </div> <% end %>
i need users hatched in order. order ('sum (posts.views)
the problem screen displays following error message:
wrong number of arguments (0 1)
it's group
, not group_by
def popular_diary @users = user.joins(:posts).group(:user_id).order('sum(posts.views)') end
Comments
Post a Comment