更新:我稍微改变了我的模型,但它仍然不起作用。我收到以下错误消息:ActionController::RoutingError (undefined local variable or method `stop_words_finder' for #< Class:0x007facb57f6908 >)
模型/pool.rb
class Pool < ActiveRecord::Base
include StopWords
attr_accessible :fragment
def self.delete_stop_words(data)
words = data.scan(/\w+/)
stop_words = stop_words_finder
key_words = words.select { |word| !stop_words.include?(word) }
pool_frag = Pool.create :fragment => key_words.join(' ')
end
end
lib/stop_words.rb
module StopWords
def stop_words_finder
%w{house}
end
end
控制器/tweets_controller.rb
class TweetsController < ApplicationController
def index
@tweets = Pool.all
respond_with(@tweets)
end
end