【发布时间】:2011-07-12 15:30:40
【问题描述】:
我有这个模型
#post.rb
class Post < ActiveRecord::Base
belongs_to :user
after_initialize :create_token
attr_accessible :token
protected
def create_token
self.token = "#{Digest::MD5.hexdigest("#{self.id}")[0,4]}"
end
end
在rails c
Post.find(:all,:conditions => { :user_id => 11})
=> [#<Post id: 26, content: "<p><strong>Yao Ming</strong> (<a shape=\"rect\" title...", user_id: 11, created_at: "2011-07-12 15:08:30", updated_at: "2011-07-12 15:08:30", title: "Yao Ming", guid: "0010f6c3-040b-4e13-aa38-3a002e6f2022", contentHash: "\xB9\\\xCBK\xB0A>4\xC4~\xFC\"\xEA7\xA6y", token: "4e73">]
当token: "4e73",但是当我尝试
Post.find(:all,:conditions => { :user_id => 11, :token => "4e73"})
=> []
我收到[],为什么?
更多信息
Post.find(:all,:conditions => { :user_id => 11}).first.token.class
=> String
Post.find(:all,:conditions => { :user_id => 11}).first.token
=> "3769"
【问题讨论】:
-
Post.find(:all,:conditions => { :token => "4e73"})你能得到什么 -
Post.find(:all,:conditions => { :token => "4e73"}) => []
-
还有
Post.find(:all,:conditions => { :user_id => 11}).first.token.class? -
Post.find(:all,:conditions => { :user_id => 11}).first.token.class => String
标签: ruby-on-rails ruby-on-rails-3 rails-models