Created
November 20, 2016 20:40
-
-
Save markburns/ce3c11968184d41427ada40adb04694e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Products | |
class ProductsController < ApplicationController | |
prepend DomainConcepts | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources :products, module: 'products' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment