Reputation: 2753
I'm trying to sort ordered by updated_at
of User
record, which is associated from Code
table.
@codes = Code.joins(:user).where('body like ?', "%"+params[:search]+"%").order('user.updated_at DESC').page(params[:page]).per(10)
However, it won't let me sort:(
This is the error message I get.
Error Message
Mysql2::Error: Unknown column 'user.created_at' in 'order clause
Upvotes: 0
Views: 304
Reputation: 38645
Your database table should be users
not user
(plural not singular). Update your order method as follows:
order('users.updated_at DESC')
Upvotes: 2