我目前在我的發佈模型上獲取了以下錯誤,該標記和通道位於act_as_taggable_on下。某些實例方法在acts_as_taggable中未定義
undefined local variable or method `tag_list_on' for #
<ActiveRecord::Relation:0x007f9864675b48>
我覺得rails無法檢測到tag_list_on或set_tag_list_on方法的存在;但是,它確實檢測了tagged_with方法,其源與其他文件位於完全相同的模塊中。
RubyMine可以檢測到所有這些方法的存在很好順便說一句。
以下是我正在執行所有這些操作的代碼部分。
@posts = Post.tagged_with(params[:tags]).paginate(:page => params[:page]|| 1, :per_page => 20)
user_tags = @posts.tag_list_on(:tags)
custom_tags = user_tags - params[:tags]
@posts.set_tag_list_on(:customs, custom_tags)
@tags = @posts.tag_counts_on(:customs, :order => "count desc").limit(10)
@channels = @posts.tag_counts_on(:channels, :order => "count desc")
真棒每個實例,但儘管告訴我。爲什麼他們只在ActiveRecord :: Relation中擴展使用某些方法,但並非所有主要方法都可能經常一起使用。 – jab 2012-08-09 19:43:39
另外,你將如何去設置正確生成的標籤列表?如果我爲post的每個實例調用set_tag_list_on,然後調用@ posts.tag_counts_on(:customs,:order =>「count desc」)。我認爲我沒有得到正確的行爲。 – jab 2012-08-09 20:37:43