简体   繁体   中英

retain object value of each user ruby on rails

I have developed two rest API for my android app in ROR. The idea is, when user clicks to get last '24' hour data, my api return the data from last 24 hours.

but in addition, after this query I use the received object of 24 hours in new Rest API call method called as SHOW for some other filtering.

here is my code

def index
    json = Hash.new
    if not ReturnbackHelper.check(params)
        render :status => :unauthorized, :json => "unauthorized"
        return
    end
    @r = ReturnHelper.filter(params)
    if(params[:selector] == '24')
        json = ReturnTimeHelper.tffilter(params, @r)
    else
        json = ReturnTimeHelper.otherfilter(params, @r)
    end
    puts json.to_json
    render :status => :ok, :json => json
end                                                                                          


def show                                                                                                
    if (params[:selector] == '24')
        @s = ReturnDiaHelper.tffilter(params, @r)
    else
        @s = ReturnDiaHelper.otherfilter(params, @rs)
    end
    render :status => :ok, :json => @s
end

So the problem is when user query for 24 hour data which I am using in show method as well, it work fine but if other user query for the 24 hour data then the object for the last user also get updated with new one with the data of new user. so how can i retain the object per user and destroy it once new query is made..

I am new in ruby, so any pointer to fix it. I hope i am clear

You are using class variable @@r , so whenever a use is making request its getting updated.
use instance variable @r and it would work.
Also read diff b/w instance variable and class variable in ruby and there uses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM