Reputation: 13354
Is it possible to do something like the following?
class PageController < ApplicationController
before_action :set_page, <send parameter `with_includes` to `set_page` as boolean based on conditions>
...
private
def set_page(with_includes = true)
@page = default ? Page.includes(:child) : Page
end
end
Upvotes: 1
Views: 1498
Reputation: 3201
It's possible to call before_action
with a lambda function:
before_action -> { set_page(your_condition_here) }
Or with a block
before_action do
set_page(your_condition_here)
end
Upvotes: 2