スコープと構文のエラーがあり、スタックオーバーフローに関する多くの例がありますが、解決できない場合は、助けてください。Scope - Rails 4との関連付けによるユーザーリストのオーダー
- 私は会社名によってユーザーのリストを注文スコープを作成しようとしています
- 1は親切に私は、ユーザーのリストを表示することができる午前スコープを書くために正しい方法で私に助言でしたが、その仕入
models
user.rb
belongs_to :company
scope :company_order, ->() { joins(:company).where('company.companyname desc') }
company.rb
has_many users
schema
users
t.string "name",
t.string "email",
t.integer "company_id"
companies
t.string "companyname",
で注文して
views file
<% @users.company_order.each do |user| %>
<div class="tablerow">
<div class="tablecell">
<div>e: <%= link_to user.name, '#' %></div>
<div>t: <%= link_to user.email.tel, '#' %></div>
</div>
<div class="tablecell">
<div>Company</div>
<div><%= user.company.companyname %></div>
</div>
</div>
<% end %>
私の範囲:scope :company_order, ->() { joins(:company).where('company.companyname desc') }
とビュー<% @users.company_order.each do |user| %>
でそれを呼び出すことが、私は以下の構文エラーを取得しようとした:
error
SQLite3::SQLException: near "desc": syntax error: SELECT "users".* FROM "users" INNER JOIN "companies" ON "companies"."id" = "users"."company_id" WHERE (company.companyname desc)
could one kindly advise me on the correct way to write a scope where i am able to display the list of users but order them by their companyname
ありがとうございました! @murifoX – ARTLoe