First of all, you must put all the methods for storing and collecting data in resources and models so that they are accessible from all controllers. However, you can save internal data change operations in your individual controllers. Once you have organized it this way, you can do what Hobo does: create a controller for the first page only, "front_controller" if you want. Here you can display data collected from all your models and resources, as well as links to other actions of your controller.
Here are some interesting thoughts on better organizing your models and controllers (thick models, skinny controllers are a rule of thumb. Since you said you use a different API (like lastfm and twitter), you can take a look at this railscasts about creating models without ActiveRecord ( models that are not database bound)
here is some kind of pseudo code, keep in mind that it really only focuses on your question.
# pseudo code class TwitterController < ApplicationController def index @services = { :twitter => TwitterModel.find(:all, ...), } end def update_twitter TwitterUpdaterClass.update { |twit| _m = TwitterModel.new _m.message = twit.msg _m.from = twit.from # .. _m.save } end end class MyIndexController < ApplicationController def index @services = { :twitter => TwitterModel.find(:all, ...), :lastfm => LastFmModel.find(:all, ...) } end end
it might be much better for background employees to update your leisure services, rather than a controller that needs to be called up every time you want to get the latest tweets. here is a good article showing - 6 ways to run background jobs in rubyonrails
# more pseudo code class TwitterWorker < BackgrounDRb::MetaWorker set_worker_name :twitter_worker def create(args = nil) # instead of TwitterController.update_twitter TwitterUpdaterClass.update { |twit| _m = TwitterModel.new _m.message = twit.msg _m.from = twit.from # .. _m.save } end end
lian
source share