Rails has a convenient method with_options for reusing options on rails methods.
On the documentation we can see how to use on
ActiveRecord classes but as this method is under Rails
Object it actually can be used on several other places, like controllers.
Check this out:
class PostsController < ApplicationController before_action :require_login, only: [:show, :edit] before_action :load_post_extra_info, only: [:show, :edit] ... end
class PostsController < ApplicationController with_options only: [:show, :edit] do before_action :require_login before_action :load_post_extra_info end ... end
Thanks @mattpolito for that!Tweet