ruby on rails - Need to store query result instead of storing query in ActiveRecord -


i having following function find of selected records public pages.

    def find_public_page(title)       @footer_public_pages ||= publicpage.where(title: %w(welcome_to_toylist terms_of_services buying_a_toy selling_a_toy requesting_a_toy ad_guildelines))       @footer_public_pages.find_by(title: title)     end 

what need @footer_public_pages should store result set in first time , on next time directly hit find_by query instead of firing 2 queries.

any appreciated.

you can try this. hope you.

def find_public_page(title)   @footer_public_pages ||= publicpage.where(title: %w(welcome_to_toylist terms_of_services buying_a_toy selling_a_toy requesting_a_toy ad_guildelines)).group_by(&:title)   @footer_public_pages[title].first unless @footer_public_pages[title].blank? end 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -