Rails:SQL 错误
我收到一个 SQL 错误:
Model:
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :entry
attr_accessible :body
validates :user_id, :presence => true
validates :entry_id, :presence => true
validates :body, :presence => true, :length => {:minimum => 10, :maximum => 5000} #spam/stupid protection
default_scope :order => 'comments.created at sec'
end
Controller
def show
@entry = Entry.find(params[:id])
@comments = @entry.comments.all
...
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @entry }
end
end
视图很简单:
<% if @entry.state > 2 %>
<section id="comments">
<% @comments.each do |comment| %>
...loop some stuff...
I'm getting a SQL error with this:
Model:
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :entry
attr_accessible :body
validates :user_id, :presence => true
validates :entry_id, :presence => true
validates :body, :presence => true, :length => {:minimum => 10, :maximum => 5000} #spam/stupid protection
default_scope :order => 'comments.created at sec'
end
Controller
def show
@entry = Entry.find(params[:id])
@comments = @entry.comments.all
...
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @entry }
end
end
The view is a simple:
<% if @entry.state > 2 %>
<section id="comments">
<% @comments.each do |comment| %>
...loop some stuff...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您想要
:order => 'comments.created_at desc'
,而不是sec
。It looks like you want
:order => 'comments.created_at desc'
, notsec
.您收到的错误到底是什么?
我认为你的错误来自这里:
因为
comments.created at sec
你不能在数据库中拥有该字段And what exactly is the error you are receiving?
I think your error is from here:
Because
comments.created at sec
you can't have that field in DB