undefined方法`join'代表“”:我的状态Feed上的字符串

时间:2011-08-24 19:45:00

标签: ruby-on-rails ruby-on-rails-3

所以我一直关注this guide根据您关注的成员(也在指南中)制作状态Feed,但我在上收到undefined method错误加入“我在代码中没有看到。

这就是我模型中的内容(或者我的微博模型)

    **tattoo.rb**
          #def self.from_members_followed_by(member)
          #  where(:member_id => member.following.push(member))
          #end

          default_scope :order => 'tattoos.created_at DESC'
- Error 2-  scope :from_members_followed_by, lambda { |member| followed_by(member) }


          private

            def self.followed_by(member)
              following_ids = %(SELECT followed_id FROM relationships WHERE follower_id = :member_id)
-Error 1 -     where("member_id IN (#{following_ids}) OR member_id = :member_id", { :member_id => member })
            end

    **member.rb**
          def feed
- Error 3-   Tattoo.from_members_followed_by(self)
          end

我想范围:from_members_followed_by取代了注释掉的函数,这就是我评论它的原因。

堆栈跟踪的错误位于:

    app/models/tattoo.rb:50:in `followed_by' - Error 1
    app/models/tattoo.rb:43:in `block in <class:Tattoo>' - Error 2
    app/models/member.rb:90:in `feed' - Error 3
    app/controllers/members_controller.rb:15:in `home'

1 个答案:

答案 0 :(得分:2)

哈!我想我明白了。

首先:不需要只调用followed_by函数的额外范围。其次:范围的参数应该是member.id,并且您将引入完整的成员。

您可以通过两种方式解决此问题。在member.rb

def feed
  Tattoo.followed_by(self.id)
end

或者,在tattoo.rb中写道:

def self.followed_by(member)
  following_ids = %(SELECT followed_id FROM relationships WHERE follower_id = :member_id)
  where("member_id IN (#{following_ids}) OR member_id = :member_id", { :member_id => member.id })
end

希望这有帮助。