harshit
harshit

Reputation: 7951

Setting class variable in Controller Ruby

I have a controller class

class MyController < ApplicationController

    def firstMethod
       @obj = #get friends list from FB
    end

    def secondMethod
     puts @obj
    end
end

So in /my/firstMethod , i have

  <%= link_to "Likes","/my/secondMethod" %>

The method is called and page is rendered but "puts @obj" display blank.

I know one way is to use before_filter but since its a expensive operation i want to get list of friends only once.

Any pointers ?

Harshit

Upvotes: 0

Views: 309

Answers (1)

Nicolas Guillaume
Nicolas Guillaume

Reputation: 8454

I would use a before_filter and store the result in cache.

You can also use the session to store the friend list but I would avoid that except if the stored list has a controlled length.

Upvotes: 2

Related Questions