일반적으로 색인 페이지에는 필터링, 페이지, 정렬 옵션이 있습니다. 새로운 페이지를 표시하고 나간 후, 본 것과 같은 옵션으로 색인 페이지로 돌아가고 싶을 수 있습니다.Rails에서 인덱스 용 매개 변수를 기억하는 가장 좋은 방법은 무엇입니까?
그렇게하기 위해 세션에 인덱스 용 매개 변수를 저장합니다.
class ApplicationController < ActionController::Base
helper_method :index_with_params
after_filter :save_index_params, :only => [:index]
def save_index_params
session[self.class.to_s] = params
end
def index_with_params overrider={}
object = self.kind_of?(ApplicationController) ? self : controller
h = session[object.class.to_s] || {"action" => :index}
h["only_path"] = true
url_for(h.merge(overrider));
end
end
저는 세션 저장소로 ActiveRecord를 사용했습니다. 이제 쿠키를 사용하고 싶습니다. 따라서 세션은 가벼워 야합니다.
어떻게 대처합니까?
감사합니다.
샘