我希望@messages返回@folder.messages,其中列“deleted”的值不等于true。我不确定为什么会抛出SQLException。我猜我没有正确格式化删除的属性,但我不知道如何修复它。
任何帮助将不胜感激。提前致谢。
错误信息:
任何帮助将不胜感激。提前致谢。
错误信息:
ActiveRecord::StatementInvalid in MailboxController#index
SQLite3::SQLException: no such column: true: SELECT "message_copies".* FROM "message_copies" WHERE ("message_copies".folder_id = 1) AND (deleted != true)
应用程序跟踪:
app/controllers/mailbox_controller.rb:14:in `show'
app/controllers/mailbox_controller.rb:5:in `index'
Mailbox_Controller.rb
1 class MailboxController < ApplicationController
2 def index
3 current_user = User.find(session[:user_id])
4 @folder = Folder.where("user_id = #{current_user.id}").first
5 show
6 render :action => "show"
7 end
8
9 def show
10 current_user = User.find(session[:user_id])
11 @folder = Folder.where("user_id = #{current_user.id}").first
12 @msgs = @folder.messages
13 @ms = @msgs.where("deleted != true")
14 @messages = @ms.all.paginate :per_page => 10,
15 :page => params[:page], :include => :message,
16 :order => "messages.created_at DESC"
17 end
18 end
t/f
对。但是我可能错了 :). 但现在我看了你的链接 - 我错了 :) 但有人确实存储了t/f
。肯定的! - fl00rdeleted IS NULL
,deleted = NULL
在任何数据库中都不起作用,因为x = NULL
对于所有的x
都是false(即使x
本身是NULL)。我添加了一个关于NULL的快速更新。 - mu is too short@msgs.where("deleted != ?", nil)
会起作用,因为AR会将其转换为deleted != NULL
。由于NULL的独特特性,任何与NULL的比较都必须使用x IS NULL
或x IS NOT NULL
来完成。 - mu is too shortstatement.gsub('?')
这样的东西,但没有任何特殊情况下将=
更改为IS
的内容。不过,我认为发送{ :deleted => nil }
应该可以解决问题。 - mu is too short