Ruby on Rails Thursday, June 25, 2015

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

On Thu, Jun 25, 2015 at 5:56 AM, Zlodiak Zlodiak <lists@ruby-forum.com> wrote:
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)

--
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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/12a9d6c292fa4a6ff54993fcee9a1c36%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHUC_t944bwmnc6mLmS2PW%2BHXahrm3Gq23MHQGfbYduJdQGdSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment