我试图为我的工作类构建一个范围,如下所示:
class Job < ActiveRecord::Base
has_many :comments
scope :most_recent, -> {order("created_at_DESC")}
validates_presence_of :description, :title
end
但我一直收到这个错误:
ActiveRecord::StatementInvalid in Jobs#premium
Showing c:/Users/Suporte 2/classificado/job_board/app/views/jobs/premium.html.erb where line #3 raised:
SQLite3::SQLException: no such column: created_at_DESC: SELECT "jobs".* FROM "jobs" WHERE "jobs"."premium" = 't' ORDER BY created_at_DESC
Extracted source (around line #3):
1
2
3
4
5
6
<h1>Premium jobs</h1>
<%= render @jobs %>
<br>
Rails.root: c:/Users/Suporte 2/classificado/job_board
Application Trace | Framework Trace | Full Trace
app/views/jobs/premium.html.erb:3:in `_app_views_jobs_premium_html_erb__296098893_30761424'
这是我在jobs_controller.rb的索引函数:
def premium
@jobs = Job.where(premium: true).all.most_recent
end
我的premium.html.erb档案:
<h1>Premium jobs</h1>
<%= render @jobs %>
<br>
<%= link_to 'New Job', new_job_path %>
<br>
<%= link_to 'Hello World', hello_world_path %>
<%= link_to 'All Jobs', jobs_path %>
我使用的是rails 4.1.4版,有人可以帮帮我吗?
答案 0 :(得分:1)
SQLite3 :: SQLException:没有这样的列:created_at_DESC
您的工作模式中的这一行
scope :most_recent, -> {order("created_at_DESC")}
应该是
scope :most_recent, -> {order("created_at DESC")}