Complete the code to enable page caching for the 'index' action in a Rails controller.
class ProductsController < ApplicationController [1] :index def index @products = Product.all end end
The method caches_page enables page caching for the specified action in Rails controllers.
Complete the code to enable action caching for the 'show' action in a Rails controller.
class ArticlesController < ApplicationController [1] :show def show @article = Article.find(params[:id]) end end
The method caches_action enables action caching for the specified controller action.
Fix the error in the code to expire the cached page for the 'home' action.
class HomeController < ApplicationController def expire_cache [1]('/home') end end
The method expire_page is used to remove a cached page in Rails.
Fill both blanks to expire the cached action for 'show' with id parameter.
class ProductsController < ApplicationController def expire_show_cache [1](action: 'show', id: [2]) end end
Use expire_action to expire action cache and params[:id] to get the id parameter.
Fill all three blanks to cache the 'index' action with a condition to skip caching if user is logged in.
class PostsController < ApplicationController [1] :index, if: -> { ![2] } private def [3] current_user.present? end end
Use caches_action to cache the action, and a method like user_logged_in? to check login status.