Skip to content

Instantly share code, notes, and snippets.

@markburns
Created November 20, 2016 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markburns/ce3c11968184d41427ada40adb04694e to your computer and use it in GitHub Desktop.
Save markburns/ce3c11968184d41427ada40adb04694e to your computer and use it in GitHub Desktop.
module DomainConcepts
def self.prepended(base)
base.class_eval do
before_action :set_view_paths
end
end
%i(index show edit new).each do |a|
define_method a do
super()
render_template a
end
end
private
def set_view_paths
prepend_view_path Rails.root.join("app/concepts/#{namespace}/views")
end
def namespace
self.class.name.deconstantize
end
def render_template(*args)
options = args.extract_options!
options[:template] = params[:action]
render(*(args << options))
end
end
pr
module Products
class ProductsController < ApplicationController
prepend DomainConcepts
end
end
resources :products, module: 'products'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment