views:

14

answers:

1

Hi all,

I have a controller called twits controller .. here i have few actions to communicate with the 3rd party API.. it has few actions to authenticate and few actions to get some values with the help of API. Now i have another controller called home and in the index page of this controller i have to call the actions of the twits controller and this should happen while the index page is getting rendered. Please advice.

A: 

Calling actions of one controller into another is generally a bad idea. You should extract the functionality into a module or a class and use it in both controllers.

So in your case, you should be writing a wrapper class for communicating with the 3rd party API and then use that wrapper. Note that this wrapper class not an abstracted wrapper for general use, but functionality that your legacy code provides, which you intend to reuse.

Hope this helps. If it isn't, try posting some code and maybe I can suggest something more.

Swanand
def direct_messages if current_user.has_twitter_oauth? @T_OAUTH = TwitterOAuth::Client.new( :consumer_key => "13OwrOWn1Qw6hpZVYkaJdA", :consumer_secret => "qaoLH9Ia5cCkQ9cCkPE9uVpEI0h6ypKuBf17tGqbd2M", :token => current_user.twitter_account.token, :secret => current_user.twitter_account.secret ) if @T_OAUTH.authorized? and @T_OAUTH.messages# id = Stream.find_since_id @messages_hash = @T_OAUTH.messages ----------------- this @message_hash i need it another controllers view..
Sumeru Suresh
This should be refactored to be in the `User` model. The `consumer_key` and `consumer_secret` should be in config files.
Swanand
We have many 3rd party services to be called. If everything goes into the user model it will be messy right. That is why we have kept different controllers for different API calls.
Sumeru Suresh