0
在我的Rails 3.1應用程序中。我有幾個控制器調用這個代碼塊:我應該把它變成一個模塊嗎?
twitter_entertainment_users = Rails.cache.fetch('twitter_entertainment_users', :expires_in => 24.hours) do
begin
Timeout.timeout(10.seconds) do
Twitter.suggestions('entertainment')
puts "#{Twitter.rate_limit_status.remaining_hits.to_s} Twitter API request(s) remaining this hour"
end
rescue Twitter::NotFound
end
end
而不是重新輸入這個代碼塊到處。我應該在模塊中使用這個嗎?即讓事情保持乾爽?
如果是這樣,該去哪裏?我讀了一些關於將模塊代碼放入app/concerns/foobar.rb
的地方。
還有其他方法嗎?尋找建議/文章。