0
根據幾個人的建議,我被告知要儘可能簡潔地控制我的控制器。目前我在我的控制器中有:從控制器到模型的移動方法
class SearchesController < ApplicationController
def index
raw_result = params[:search] ||= "man on fire"
result = raw_result.gsub(/\s+/, "+")
movie_details = HTTParty.get("http://imdbapi.org/?title="+result+"&type=json")
@searches = ActiveSupport::JSON.decode(movie_details)
end
end
如何將它變成我的模型中的新類並在控制器中再次調用它?
當前模型和控制器:
class IMDBSearcher
def self.search(search)
raw_result = search || "man on fire"
result = raw_result.gsub(/\s+/, "+")
movie_details = HTTParty.get("http://imdbapi.org/?title="+result+"&type=json")
ActiveSupport::JSON.decode(movie_details)
end
end
class SearchesController < ApplicationController
def index
@searches = IMDBSearcher.search(params[:search])
end
end
我得到的觀點的錯誤:未初始化不斷SearchesController :: IMDBSearcher – emailnitram 2013-03-01 23:06:59
奇怪,'IMDBSearcher'是在你的模型應用程序,不是?你能發佈你的控制器和型號代碼嗎? – Kaeros 2013-03-01 23:10:21
我用我現在的模型和控制器更新了這個問題。雙重檢查拼寫不知道爲什麼我得到那個錯誤 – emailnitram 2013-03-01 23:20:03